Cod sursa(job #412661)
Utilizator | Agape Mihai b_polar | Data | 5 martie 2010 20:58:22 |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <stdio.h>
#define NMAX 102
#define FOR(a) for(a=1;a<=N;a++)
int c[NMAX][NMAX],N,i,j,k;
int main()
{
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
scanf("%d",&N);
FOR(i)FOR(j)scanf("%d",&c[i][j]);
FOR(k)FOR(i)FOR(j)
if( i!=j && c[i][k] && c[k][j] && (c[i][k]+c[k][j]<c[i][j] || !c[i][j] ))c[i][j]=c[i][k]+c[k][j];
FOR(i)
{
FOR(j)printf("%d ",c[i][j]);
printf("\n");
}
}