Pagini recente » Rating Andrei Istrate (andrei.istrate) | Diferente pentru runda/carantinanuneopresteagmbiruieste intre reviziile 2 si 3 | Monitorul de evaluare | Cod sursa (job #3134789) | Cod sursa (job #3141544)
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAX_N = 100;
int n;
int dp[MAX_N + 1][MAX_N + 1];
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
cin >> dp[i][j];
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
if(dp[i][j] == 0 && i != j)
dp[i][j] = INF;
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
if(dp[i][k] != INF && dp[k][j] != INF)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
cout << dp[i][j] << " ";
cout << "\n";
}
return 0;
}