Pagini recente » Cod sursa (job #1246864) | Cod sursa (job #2091528)
#include <fstream>
using namespace std;
const int INF = 1e5, NMAX = 100;
int n, a[NMAX + 5][NMAX + 5];
int main() {
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
cin >> n;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
cin >> a[i][j];
if(i != j && a[i][j] == 0)
a[i][j] = INF;
}
}
for(int k = 1; k <= n; ++k) {
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(a[i][j] > a[i][k] + a[k][j])
a[i][j] = a[i][k] + a[k][j];
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(a[i][j] == INF)
cout << "0 ";
else
cout << a[i][j] << " ";
}
cout << "\n";
}
return 0;
}