Pagini recente » Cod sursa (job #1853109) | Istoria paginii utilizator/anna_cristina | Cod sursa (job #719921) | Cod sursa (job #1824318) | Cod sursa (job #2611414)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
//int n,a[105][105],i,j,x,k;
const int NMAX = 105;
const int INF = 1e9;
int n, dist[NMAX][NMAX];
int main()
{
f >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dist[i][j] = INF;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
int x;
f >> x;
if(x != 0) {
dist[i][j] = x;
}
}
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(dist[i][k] + dist[k][j] < dist[i][j] && i != j) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(dist[i][j] == INF) {
g << 0 << ' ';
} else {
g << dist[i][j] << ' ';
}
}
g << '\n';
}
return 0;
}