Pagini recente » Cod sursa (job #2976964) | Cod sursa (job #2185300) | Cod sursa (job #1075247) | Cod sursa (job #27153) | Cod sursa (job #3251471)
#include <bits/stdc++.h>
using namespace std;
string file="royfloyd";
ifstream fin(file+".in");
ofstream fout(file+".out");
int dist[1001][1001];
void royfloyd(int n)
{
for (int k=1; k<=n; k++){
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
}
int main()
{
int n;
fin>>n;
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
fin>>dist[i][j];
}
}
royfloyd(n);
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
fout<<dist[i][j]<<" ";
}
fout<<"\n";
}
return 0;
}