Pagini recente » Cod sursa (job #317048) | Cod sursa (job #2636629) | Cod sursa (job #2154306) | Cod sursa (job #1972575) | Cod sursa (job #2568583)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int DIM = 101;
int dist[DIM][DIM];
main()
{
int n;
fin >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
fin >> dist[i][j];
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(dist[i][k] && dist[k][j] && i != j && (!dist[i][j] || dist[i][j] > dist[i][k] + dist[k][j]))
dist[i][j] = dist[i][k] + dist[k][j];
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
fout << dist[i][j] << ' ';
fout << '\n';
}
}