Cod sursa(job #891822)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n; fin >> n;
vector<vector<int> > dist(n, vector<int>(n, 1<<21));
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
fin >> dist[i][j];
if (i!=j && dist[i][j]==0)
dist[i][j]=1<<21;
}
}
for (int k=0; k<n; ++k)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
dist[i][j] = min( dist[i][j], dist[i][k] + dist[k][j] );
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j)
fout << (dist[i][j]>(1<<20) ?0 :dist[i][j]) << ' ';
fout << '\n';
}
return 0;
}