Pagini recente » Cod sursa (job #2242997) | Cod sursa (job #1597163) | Cod sursa (job #1943369) | Cod sursa (job #419211) | Cod sursa (job #1706558)
#include <iostream>
#include <fstream>
using namespace std;
#define N_MAX 100
int costuri[N_MAX + 1][N_MAX + 1];
int main()
{
ios::sync_with_stdio(false);
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
fin >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
fin >> costuri[i][j];
for(int k = 1; k <= n; ++k){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(i != k && i != j && k != j && costuri[i][k] > 0 && costuri[k][j] > 0){
if(costuri[i][j] > costuri[i][k] + costuri[k][j] || costuri[i][j] == 0)
costuri[i][j] = costuri[i][k] + costuri[k][j];
}
}
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j)
fout << costuri[i][j] << " ";
fout << "\n";
}
return 0;
}