Pagini recente » Cod sursa (job #1512195) | Cod sursa (job #541819) | Cod sursa (job #1453202) | Cod sursa (job #1948177) | Cod sursa (job #3256233)
#include "bits/stdc++.h"
const int SIZE = 100;
int dist[SIZE + 5][SIZE + 5];
int n;
void Debug(){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
std :: cout << dist[i][j] << ' ';
}
std :: cout << '\n';
}
}
void Floyd(){
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(dist[i][j] > dist[i][k] + dist[k][j]){
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
}
void Solve(){
std :: cin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
std :: cin >> dist[i][j];
}
}
Floyd();
Debug();
}
signed main(){
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
std :: ios_base :: sync_with_stdio(false);
std :: cin.tie(0);
std :: cout.tie(0);
Solve();
return 0;
}