Pagini recente » Cod sursa (job #3162211) | Borderou de evaluare (job #3272912) | Cod sursa (job #1974303) | Cod sursa (job #3274602) | Cod sursa (job #3231410)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int nmax = 101;
const int inf = 0x3F3F3F3F;
int n,mat[nmax][nmax];
void read_input(){
fin >> n;
for(int i = 1; i <=n; i++){
for(int j = 1; j <=n; j++){
fin >> mat[i][j];
if(mat[i][j] == 0 && i != j){
mat[i][j] = inf;
}
}
}
}
void solve(){
for(int k = 1; k <=n; k++){
for(int i = 1; i <=n; i++){
for(int j = 1; j <=n; j++){
if(mat[i][j] > mat[i][k] + mat[k][j]){
mat[i][j] = mat[i][k] + mat[k][j];
}
}
}
};
for(int i = 1; i <=n; i++,fout << '\n'){
for(int j = 1; j <=n; j++){
fout << mat[i][j] << " ";
}
}
}
int main(){
read_input();
solve();
return 0;
}