Cod sursa(job #2307559)
Utilizator | alehandru69 adriashkin.07 | Data | 24 decembrie 2018 21:35:00 |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fs first
#define sc second
int n,A[200][200];
int main()
{
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>A[i][j];
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j && A[i][k]&&A[k][j]&&(!A[i][j]||(A[i][k]+A[k][j]<A[i][j]))) A[i][j]=A[i][k]+A[k][j];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
}