Mai intai trebuie sa te autentifici.
Cod sursa(job #341997)
| Utilizator | Data | 20 august 2009 11:55:54 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
#include <cstdio>
#define REP(i,n) for((i)=0;(i)<(n);++(i))
using namespace std;
int N;
int A[100][100];
int main() {
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
int i,j,k;
scanf("%d",&N);
REP(i,N) REP(j,N) scanf("%d",&A[i][j]);
REP(k,N) REP(i,N) REP(j,N)
if (i != j)
if (A[i][k] && A[k][j])
if ((A[i][j] > A[i][k] + A[k][j]) || (!A[i][j]))
A[i][j] = A[i][k] + A[k][j];
REP(i,N) { REP(j,N) printf("%d ",A[i][j]);printf("\n");};
fclose(stdin);
fclose(stdout);
return 0;
}
