Pagini recente » Cod sursa (job #3359084) | Cod sursa (job #3360238) | Cod sursa (job #3360239) | Monitorul de evaluare | Cod sursa (job #3360232)
#include <bits/stdc++.h>
using namespace std;
ifstream f;
ofstream g;
const int nmax = 100;
const int inf = 1'000'000'000;
int dist[nmax][nmax];
int main() {
f.open("royfloyd.in");
g.open("royfloyd.out");
int n; f >> n;
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++)
f >> dist[i][j],
i != j && !dist[i][j] ? dist[i][j] = inf : 0;
for(int i, j, k = 0; k < n; k ++)
for(i = 0; i < n; i ++)
for(j = 0; j < n; j ++)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
for(int i = 0, j; i < n; i ++)
for(j = 0; j < n; j ++)
g << (dist[i][j] == inf ? 0 : dist[i][j]) << " \n"[j == n - 1];
}