Pagini recente » Cod sursa (job #27724) | Cod sursa (job #325159) | Cod sursa (job #33097) | Cod sursa (job #1022511) | Cod sursa (job #1725523)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
int n;
int dist[105][105];
int main() {
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
cin >> dist[i][j];
if (!dist[i][j] && i != j)
dist[i][j] = 1001;
}
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; cout << "\n", i++)
for (int j = 0; j < n; j++)
cout << (dist[i][j] > 1000? 0 : dist[i][j]) << " ";
return 0;
}