Cod sursa(job #2924008)
| Utilizator | Data | 22 septembrie 2022 21:05:34 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.74 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
vector <int> V[105];
int n,m,dist[105][105];
int main()
{
fin>>n;
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
fin>>dist[i][j];
}
}
for(int k = 1;k<=n;k++)
for(int j = 1;j<=n;j++)
for(int i = 1;i<=n;i++)
{
if(dist[i][k] && dist[k][j])
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
fout<<dist[i][j]<<' ';
}
fout<<'\n';
}
}
