Pagini recente » Cod sursa (job #1015491) | Cod sursa (job #3355812) | Cod sursa (job #2333263) | Cod sursa (job #1108905) | Cod sursa (job #3345114)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18;
ifstream fin("royfloyd.in"); ofstream fout("royfloyd.out");
int main(){
int n; fin>>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; fin>>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) fout<<"0 ";
else fout<<dist[i][j]<<" ";
}
fout<<'\n';
}
}