Cod sursa(job #2343520)
| Utilizator | Data | 14 februarie 2019 08:19:43 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <bits/stdc++.h>
#define MAX 1010
#define INF 999999999
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int cost[MAX][MAX];
int main()
{int i,j,k;
fin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{fin>>cost[i][j];
if(!cost[i][j] && i!=j)
cost[i][j]=INF;
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(k!=i && k!=j)
{
cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
}
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
fout<<cost[i][j]<<' ';
fout<<'\n';
}
}
