Pagini recente » Cod sursa (job #2636980) | Cod sursa (job #1653328) | Cod sursa (job #3206295) | Cod sursa (job #2938726) | Cod sursa (job #2354618)
#include <fstream>
#define INF 101
#define NMAX 101
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int D[NMAX][NMAX];
void read();
void run();
void print();
int main(){
read();
run();
print();
return 0;
}
void read(){int i, j;
fin >> n;
for(i = 1 ; i <= n; i++)
for(j = 1; j <= n; j++){
fin >> D[i][j];
if(!D[i][j] && i != j) D[i][j] = INF;
}
}
void run(){int x, y, z;
for(z = 1; z <= n; z++)
for(x = 1; x <= n; x++)
for(y = 1; y <= n; y++)
if(D[x][y] > D[x][z] + D[z][y])
D[x][y] = D[x][z] + D[z][y];
}
void print(){int i, j;
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++)
if(D[i][j] != INF) fout << D[i][j] << ' ';
else fout << "0 ";
fout << '\n';
}
fout.close();
}