Mai intai trebuie sa te autentifici.
Cod sursa(job #530487)
| Utilizator | Data | 7 februarie 2011 21:09:15 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <fstream>
using namespace std;
#define INF 1<<30
#define NMAX 101
int N, mat[NMAX][NMAX];
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int main(void)
{
int i, j;
f >> N;
for (i=1;i<=N;i++)
for (j=1;j<=N;j++){
f >> mat[i][j];
if (i!=j && mat[i][j] == 0) {
mat[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 (mat[i][j] > mat[i][k]+mat[k][j])
mat[i][j] = mat[i][k]+mat[k][j];
for (int i=1;i<=N;i++) {
for (int j=1;j<=N;j++)
g<<mat[i][j]<<" ";
g<<"\n";
}
f.close(); g.close();
return 0;
}
