Pagini recente » Cod sursa (job #3164003) | Cod sursa (job #1626197) | Cod sursa (job #2277429) | Cod sursa (job #3209949) | Cod sursa (job #2686085)
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int INF = 1000000;
int dist[105][105],n;
int main()
{
in>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
dist[i][j] = i==j ? 0 : INF;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
in>>dist[i][j];
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if (dist[i][k]==INF || dist[k][j]==INF)
continue;
if(dist[i][k]+dist[k][j]<dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
if(i==j || dist[i][j]==INF)
out<<0<<' ';
else
out<<dist[i][j]<<' ';
out<<'\n';
}
return 0;
}