Mai intai trebuie sa te autentifici.
Cod sursa(job #3030667)
| Utilizator | Data | 17 martie 2023 19:59:49 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.69 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,d[105][105];
int main()
{
fin>>n;
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
fin>>d[i][j];
}
}
for(int k = 1;k<=n;k++)
{
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
if(d[i][j]>d[i][k] + d[k][j])
d[i][j] = d[i][k] + d[k][j];
}
}
}
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
fout<<d[i][j]<<' ';
}
fout<<'\n';
}
}
