Pagini recente » Cod sursa (job #637709) | Cod sursa (job #2098965) | Cod sursa (job #410545) | Cod sursa (job #1661798) | Cod sursa (job #2594771)
#include <stdio.h>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 0x3f3f3f3f;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
const int Nmax = 101;
int a[Nmax][Nmax];
int main(void) {
int N;
fin >> N;
rep(i,N)
rep(j,N) {
fin >> a[i][j];
if (i != j && a[i][j] == 0) {
a[i][j] = INF;
}
}
rep(k,N)
rep(i,N)
rep(j,N) {
if (a[i][k] + a[k][j] < a[i][j]) {
a[i][j] = a[i][k] + a[k][j];
}
}
rep(i,N) {
rep(j,N) {
fout << (a[i][j] == INF ? 0 : a[i][j]) << ' ';
}
fout << '\n';
}
return 0;
}