Pagini recente » Cod sursa (job #2237516) | Cod sursa (job #185193) | Cod sursa (job #1975267) | Cod sursa (job #2490234) | Cod sursa (job #2718860)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int a[105][105], dist[105][105];
int main()
{
int N;
fin >> N;
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
fin >> a[i][j];
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
dist[i][j] = a[i][j];
for(int aux = 1; aux <= N; aux++)
for(int src = 1; src <= N; src++)
for(int sink = 1; sink <= N; sink++)
if(dist[src][aux] && dist[aux][sink])
dist[src][sink] = min(dist[src][sink], dist[src][aux] + dist[aux][sink]);
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= N; j++)
fout << dist[i][j] << " ";
fout << '\n';
}
return 0;
}