Pagini recente » Cod sursa (job #819928) | Cod sursa (job #2793879) | Cod sursa (job #1067742) | Cod sursa (job #1838690) | Cod sursa (job #1768183)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: royfloyd.cpp
* Author: octavian
*
* Created on 30 September 2016, 11:31
*/
#include <cstdlib>
#include <algorithm>
using namespace std;
int N;
const int NMAX = 105;
const int INF = 1000000005;
int dist[NMAX][NMAX];
/*
*
*/
int main(int argc, char** argv) {
FILE *fin = fopen("royfloyd.in", "r");
FILE *fout = fopen("royfloyd.out", "w");
fscanf(fin, "%d", &N);
for(int i = 1 ; i <= N ; i++) {
for(int j = 1 ; j <= N ; j++) {
fscanf(fin, "%d", &dist[i][j]);
if(dist[i][j] == 0) {
dist[i][j] = INF;
}
}
}
// for(int i = 1 ; i <= N ; i++) {
// for(int j = 1 ; j <= N ; j++) {
// fprintf(fout, "%d ", dist[i][j]);
// }
// fprintf(fout, "\n");
// }
//
for(int k = 1 ; k <= N ; k++) {
for(int i = 1 ; i <= N ; i++) {
for(int j = 1 ; j <= N ; j++) {
if(i != j) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
}
for(int i = 1 ; i <= N ; i++) {
for(int j = 1 ; j <= N ; j++) {
if(dist[i][j] == INF) {
fprintf(fout, "0 ");
} else {
fprintf(fout, "%d ", dist[i][j]);
}
}
fprintf(fout, "\n");
}
fclose(fin);
fclose(fout);
return 0;
}