Pagini recente » Cod sursa (job #354409) | Cod sursa (job #308673) | Cod sursa (job #605367) | Cod sursa (job #1392369) | Cod sursa (job #3192655)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int c[107][107];
int main(){
fin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
fin >> c[i][j];
if(c[i][j] == 0){
c[i][j] == 1000000;
}
}
}
for(int z = 1; z <= n; z++){
for(int x = 1; x <= n; x++){
for(int y = 1; y <= n; y++){
if(c[x][z] + c[z][y] < c[x][y]){
c[x][y] = c[x][z] + c[z][y];
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(c[i][j] != INT_MAX) fout << c[i][j] << " ";
else fout << 0 << " ";
}
fout << endl;
}
return 0;
}