Cod sursa(job #2289379)
Utilizator | Stefan Zamfir StefanZamfir | Data | 24 noiembrie 2018 15:11:30 |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.64 kb |
#include <iostream>
using namespace std;
int weight[100][100];
int main() {
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
cin >> weight[i][j];
}
}
for(int k=0;k<n;++k){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
weight[i][j] = min(weight[k][j] + weight[i][k],weight[i][j]);
}
}
}
for(int i=0;i<n;++i,cout << '\n'){
for(int j=0;j<n;++j){
cout << weight[i][j] << ' ';
}
}
}