Pagini recente » Cod sursa (job #1707844) | Cod sursa (job #1764175) | Cod sursa (job #1237969) | Cod sursa (job #155226) | Cod sursa (job #1528111)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
typedef long long int ll;
#define REP(i, a, b) \
for (int i=int(a); i<=int(b); ++i)
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
#define N 101
#define INF 10000
int G[N][N];
int n;
void read() {
f >> n;
REP (i, 1, n)
REP (j, 1, n)
f >> G[i][j];
}
void royfloyd() {
int dist[N][N];
REP (i, 1, n)
REP (j, 1, n)
if (i == j)
dist[i][j] = 0;
else if (G[i][j] == 0)
dist[i][j] = INF;
else
dist[i][j] = G[i][j];
REP (k, 1, n)
REP (i, 1, n)
REP (j, 1, n)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
REP (i, 1, n) {
REP (j, 1, n)
g << dist[i][j] << " ";
g << endl;
}
}
int main () {
read();
royfloyd();
return 0;
}