Mai intai trebuie sa te autentifici.
Cod sursa(job #599503)
| Utilizator | Data | 28 iunie 2011 22:17:57 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.7 kb |
#include <iostream>
#include <fstream>
#define nmax 101
#define min(a,b) ((a)<(b))?(a):(b)
using namespace std;
int n;
int a[nmax][nmax];
void citire(){
ifstream in("royfloyd.in");
in >> n;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
in >> a[i][j];
in.close();
}
void rezolv(){
int i,j,k;
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)
for(k=1;k<=n;++k)
a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
}
void afis(){
ofstream out("royfloyd.out");
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j) out << a[i][j] << " ";
out << "\n";
}
out.close();
}
int main()
{
citire();
rezolv();
afis();
return 0;
}
