Mai intai trebuie sa te autentifici.
Cod sursa(job #2053501)
| Utilizator | Data | 31 octombrie 2017 20:16:52 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 1.01 kb |
#include <fstream>
using namespace std;
ifstream cin ("royfloyd.in");
ofstream cout ("royfloyd.out");
int n;
int mat[105][105];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
const int inf = 2e9;
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
cin>>mat[i][j];
if (mat[i][j] == 0){
mat[i][j] = inf;
}
}
}
for (int k=1; k<=n; k++){
for (int i=1; i<=n; i++){
if (k == i || mat[i][k] == 0){
continue;
}
for (int j=1; j<=n; j++){
if (i == j || mat[k][j] == 0){
continue;
}
mat[i][j] = min (mat[i][j] , mat[i][k] + mat[k][j]);
}
}
}
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
if (mat[i][j] == inf){
mat[i][j] = 0;
}
cout<<mat[i][j]<<" ";
}
cout<<'\n';
}
return 0;
}