Pagini recente » Cod sursa (job #206274) | Cod sursa (job #591908) | Cod sursa (job #2553475) | Cod sursa (job #1910983) | Cod sursa (job #3235646)
#include <vector>
#include <algorithm>
#include <queue>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int N = 100;
const int INF = 1e6;
int d[N + 1][N + 1], n;
int main() {
in >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
in >> d[i][j];
if(i != j && d[i][j] == 0){
d[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(d[i][k] + d[k][j] < d[i][j]){
d[i][j] = d[i][k] + d[k][j];
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(d[i][j] == INF){
d[i][j] = 0;
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
out << d[i][j] << " ";
}
out << '\n';
}
return 0;
}