Cod sursa(job #1818901)
Utilizator | Dominic Iorganda dominiciorganda | Data | 29 noiembrie 2016 22:25:17 |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.7 kb |
#include <iostream>
#include <cstdio>
#define inf 1e7
using namespace std;
int f[101][101],g[101][101],x,k,i,m,j;
int main()
{
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
scanf("%d",&x);
for(k=1;k<=x;k++)
{
for(i=1;i<=x;i++)
scanf("%d",&f[k][i]);
}
for(k=1;k<=x;k++)
{
for(i=1;i<=x;i++)
{
for(j=1;j<=x;j++)
{
if(f[i][j]>f[i][k]+f[k][j])
f[i][j]=f[i][k]+f[k][j];
}
}
}
for(k=1;k<=x;k++)
{
for(i=1;i<=x;i++)
printf("%d ",f[k][i]);
printf("\n");
}
return 0;
}