Pagini recente » Cod sursa (job #2361813) | Cod sursa (job #2934702) | Cod sursa (job #3278550) | Cod sursa (job #3149433) | Cod sursa (job #2638251)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n, cost[150][150];
int main() {
fin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
fin >> cost[i][j];
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i != j && cost[i][k] && cost[k][j] && (!cost[i][j] || cost[i][k] + cost[k][j] < cost[i][j]))
cost[i][j] = cost[i][k] + cost[k][j];
for (int i = 1; i <= n; i++, fout << '\n')
for (int j = 1; j <= n; j++, fout << ' ')
fout << cost[i][j];
return 0;
}