Pagini recente » Cod sursa (job #2423040) | Cod sursa (job #1131231) | Cod sursa (job #930179)
Cod sursa(job #930179)
#include <iostream>
#include <fstream>
#include <utility>
using namespace std;
#define MAXN 110
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int N, a[MAXN][MAXN];
int main()
{
int i, j , k;
fin >> N;
for(i = 0; i < N; i++){
for(j = 0; j < N; j++){
fin >> a[i][j];
}
}
for(k = 0; k < N; k++){
for(i = 0; i < N; i++){
for(j = 0; j < N; j++){
if(i != j){
a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
}
else a[i][j] = 0;
}
}
}
for(i = 0; i < N; i++){
for(j = 0; j < N; j++) fout << a[i][j] << " ";
fout << "\n";
}
return 0;
}