Pagini recente » Cod sursa (job #1790728) | Cod sursa (job #43987) | Cod sursa (job #830694) | Cod sursa (job #549360) | Cod sursa (job #3349902)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
int N;cin>>N;
int inf=10000;
int dist[N][N];
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
cin>>dist[i][j];
if(dist[i][j]==0){
dist[i][j]=inf;
}
}
}
for(int k=0;k<N;k++){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(dist[i][j]==inf || (i==j))dist[i][j]=0;
cout<<dist[i][j]<<" ";
}
cout<<'\n';
}
}