Pagini recente » Cod sursa (job #1895119) | Cod sursa (job #1014603) | Cod sursa (job #419810) | Cod sursa (job #3291267) | Cod sursa (job #2907277)
#include <bits/stdc++.h>
#define nmax 100
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int dist[nmax+5][nmax+5];
int main() {
int n; fin >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dist[i][j] = INT_MAX;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
fin >> dist[i][j];
}
}
for(int i = 1; i <= n; i++) {
dist[i][i] = 0;
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for(int i = 1; i <= n; i++, fout << "\n") {
for(int j = 1; j <= n; j++) {
if(dist[i][j] == INT_MAX) {
fout << 0 << " ";
} else {
fout << dist[i][j] << " ";
}
}
}
return 0;
}