Pagini recente » Diferente pentru home intre reviziile 130 si 131 | Cod sursa (job #199028) | Statistici Supeala Ionut (Theosupyy) | Cod sursa (job #2893607) | Cod sursa (job #2425019)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int N = 101;
const int INF = 1001;
int n;
int A[N][N];
void citire() {
fin >> n;
int x;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
fin >> x;
if (i != j)
if (x == 0) A[i][j] = INF;
else A[i][j] = x;
else A[i][j] = 0;
}
}
void RoyFloyd() {
for (int i = 1; i <= n; i++)
for (int k = 1; k <= n; k++)
for (int j = 1; j <= n; j++)
if (A[i][k] + A[k][j] < A[i][j])
A[i][j] = A[i][k] + A[k][j];
}
void afis() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=n; j++)
if (A[i][j] == INF && i != j) fout << 0 << " ";
else fout << A[i][j] << " ";
fout << '\n';
}
}
int main() {
citire();
RoyFloyd();
afis();
return 0;
}