Pagini recente » Cod sursa (job #2461136) | Cod sursa (job #2460104) | Cod sursa (job #3210986) | Cod sursa (job #2459400) | Cod sursa (job #2815017)
#include <climits>
#include <fstream>
#include <cmath>
using namespace std;
int mat[101][101];
int n;
int main(){
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
f >> n;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
f >> mat[i][j];
if(i != j && mat[i][j] == 0){
mat[i][j] = INT_MAX;
}
}
}
for(int k = 1; k <= n; ++k){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
mat[i][j] = min(mat[i][j], (mat[i][k] + mat[k][j]));
}
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
g << mat[i][j] << " ";
}
g << "\n";
}
}