Pagini recente » Cod sursa (job #2534122) | Cod sursa (job #1183806) | Cod sursa (job #1371527) | Cod sursa (job #1109456) | Cod sursa (job #2466794)
#include <bits/stdc++.h>
#define MaxN 100
using namespace std;
int best[MaxN + 1][MaxN + 1];
int N;
int main(){
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
int i, j, k;
cin >> N;
for(i = 1; i <= N; i++)
for(j = 1; j <= N; j++)
cin >> best[i][j];
for(i = 1; i <= N; i++)
for(j = 1; j <= N; j++)
if(!best[i][j]) best[i][j] = 1 << 29;
for(k = 1; k <= N; k++)
for(i = 1; i <= N; i++)
for(j = 1; j <= N; j++)
if(i != j) best[i][j] = min(best[i][j], best[i][k] + best[k][j]);
for(i = 1; i <= N; i++)
{
for(j = 1; j <= N; j++)
if(best[i][j] == 1 << 29) cout << 0 << ' ';
else cout << best[i][j] << ' ';
cout << '\n';
}
return 0;
}