Mai intai trebuie sa te autentifici.
Cod sursa(job #2865093)
| Utilizator | Data | 8 martie 2022 14:56:44 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 1.13 kb |
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <climits>
#include <unordered_map>
#define NMAX 103
using namespace std;
int n;
int mat[NMAX][NMAX];
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int main()
{
fin >> n;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
fin>>mat[i][j];
if(mat[i][j]==0)
{
mat[i][j]=-1;
}
}
mat[i][i]=0;
}
//fac roy-floyd
for(int aux=1; aux<=n; aux++)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(mat[i][j]>mat[i][aux]+mat[aux][j])
{
mat[i][j]=mat[i][aux]+mat[aux][j];
}
}
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(mat[i][j]==-1)
{
fout<<"0 ";
}
else{
fout<<mat[i][j]<<" ";
}
}
fout<<"\n";
}
return 0;
}