Pagini recente » Cod sursa (job #2891389) | Cod sursa (job #3170639) | Cod sursa (job #1985930) | Cod sursa (job #2361382) | Cod sursa (job #2856246)
/*
__
_.--"" |
.----. _.-' |/\| |.--.
| |__.-' _________| |_) _______________
| .-""-.""""" ___, `----'")) __ .-""-.""""--._
'-' ,--. ` |Cezar| .---. |:.| ' ,--. ` _`.
( ( ) ) __| 7 |__\\|// _..-- \/ ( ( ) )--._".-.
. `--' ;\__________________..--------. `--' ;--------'
`-..-' `-..-'
*/
#include <iostream>
#include <fstream>
using namespace std;
const int N = 1e2 + 5;
const int INF = (1<<28);
int mat[N][N];
int main() {
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n;
in>>n;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
in>>mat[i][j];
if(i != j && mat[i][j] == 0)
mat[i][j] = INF;
}
}
for(int k = 1;k <= n; k++){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
mat[i][j] = (mat[i][k] + mat[k][j])*(mat[i][j] > (mat[i][k] + mat[k][j])) + mat[i][j]*(mat[i][j] <=( mat[i][k] + mat[k][j]));
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(mat[i][j] == INF)
out<<0<<' ';
else out<<mat[i][j]<<' ';
}
out<<'\n';
}
return 0;
}