Pagini recente » Cod sursa (job #2908416) | Cod sursa (job #934538) | Cod sursa (job #592586) | Cod sursa (job #2399454) | Cod sursa (job #1881600)
#include <bits/stdc++.h>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int NMax = 103;
const int INF = 0x3f3f3f3f;
int n;
int a[NMax][NMax],b[NMax][NMax];
int main()
{
f >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
f >> b[i][j];
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
a[i][j] = INF;
if(b[i][j] != 0){
a[i][j] = b[i][j];
}
}
}
for(int inter = 1; inter <= n; ++inter){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(a[i][j] > a[i][inter] + a[inter][j]){
a[i][j] = a[i][inter] + a[inter][j];
}
}
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(a[i][j] == INF || i == j)
g << 0 << ' ';
else
g << a[i][j] << ' ';
}
g << '\n';
}
return 0;
}