Cod sursa(job #1464907)
| Utilizator | Data | 25 iulie 2015 22:52:12 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.71 kb |
#include<fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,i,j,k,cost[102][102];
int main(){
fin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
fin>>cost[i][j];
if(cost[i][j]==0)
cost[i][j]=5000;
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]>cost[i][k]+cost[k][j] && i!=j)
cost[i][j]=cost[i][k]+cost[k][j];
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
if(cost[i][j]!=5000)
fout<<cost[i][j]<<" ";
else
fout<<0<<" ";
fout<<'\n';
}
return 0;
}
