Cod sursa(job #2856201)
| Utilizator | Data | 23 februarie 2022 16:08:44 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.89 kb |
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int d[105][105];
const int inf=1<<20;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>d[i][j];
if(i!=j && !d[i][j])
d[i][j]=inf;
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(d[i][k]+d[k][j]<d[i][j])
d[i][j]=d[i][k]+d[k][j];
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(d[i][j]!=inf)
cout<<d[i][j]<<" ";
else
cout<<"0 ";
}
cout<<"\n";
}
return 0;
}
