Pagini recente » Cod sursa (job #87380) | Cod sursa (job #915968) | Cod sursa (job #966122) | Cod sursa (job #2613790) | Cod sursa (job #2432695)
#include <bits/stdc++.h>
using namespace std;
int cost[105][105];
int main()
{
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 >> cost[i][j];
}
for(int inter = 1; inter <= n; ++inter){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(cost[i][inter] && cost[inter][j] && i != j){
if(cost[i][j]) cost[i][j] = min(cost[i][j], cost[i][inter] + cost[inter][j]);
else cost[i][j] = cost[i][inter] + cost[inter][j];
}
}
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j)
fout << cost[i][j] << " ";
fout << "\n";
}
return 0;
}