Pagini recente » Cod sursa (job #3198423) | Cod sursa (job #2293597) | Cod sursa (job #805296) | Cod sursa (job #2172710) | Cod sursa (job #3270800)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int NMAX = 100;
const int INF = 2e9;
int n;
int g[NMAX + 1][NMAX + 1];
int d[NMAX + 1][NMAX + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fin >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
fin >> d[i][j];
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(!d[i][j] && i != j) {
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++) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for(int i = 1; i <= n; i++, fout << '\n') {
for(int j = 1; j <= n; j++) {
fout << (d[i][j] == INF ? 0 : d[i][j]) << ' ';
}
}
return 0;
}