Pagini recente » Cod sursa (job #814947) | Cod sursa (job #2160940) | Cod sursa (job #164699) | Cod sursa (job #223829) | Cod sursa (job #3345113)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18;
int main(){
int n; cin>>n;
vector<vector<ll>> dist(n+1, vector<ll>(n+1, inf));
for(int i=1; i<=n; i++) dist[i][i]=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
int x; cin>>x; if(x>0) dist[i][j]=x;
}
}
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];
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(dist[i][j]==inf) cout<<"0 ";
else cout<<dist[i][j]<<" ";
}
cout<<'\n';
}
}