Pagini recente » Cod sursa (job #1668551) | Cod sursa (job #2724654) | Cod sursa (job #1739404) | Cod sursa (job #2452320) | Cod sursa (job #3251477)
#include <iostream>
#include <fstream>
#include <vector>
//#include <bits/stdc++.h>
#define in fin
#define out fout
#define oo 1000000
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int d[1005][1005];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; in >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
in >> d[i][j];
if(d[i][j] == 0 && i != j) d[i][j] = oo;
}
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
// e mai bine sa facem i->k + k->j decat i->j?
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++) out << d[i][j] << " ";
out << '\n';
}
return 0;
}