Pagini recente » Cod sursa (job #1210543) | Cod sursa (job #307929) | Istoria paginii runda/lh.11-1/clasament | Monitorul de evaluare | Cod sursa (job #1181943)
// http://www.infoarena.ro/problema/royfloyd
#include <fstream>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; ++i)
int main() {
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int N;
in >> N;
int a[100][100];
FOR(i, N) {
FOR(j, N) {
in >> a[i][j];
}
}
FOR(k, N) {
FOR (i, N) {
FOR (j, N) {
if ((a[i][k]) && (a[k][j]) && (a[i][k] + a[k][j] < a[i][j])) {
a[i][j] = a[i][k] + a[k][j];
}
}
}
}
FOR(i, N) {
FOR(j, N) {
out << a[i][j] << " ";
}
out << endl;
}
return 0;
}