Pagini recente » Cod sursa (job #1760321) | Cod sursa (job #762185) | Cod sursa (job #986376) | Cod sursa (job #2865096)
#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]=INT_MAX;
}
}
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]==INT_MAX)
{
fout<<"0 ";
}
else{
fout<<mat[i][j]<<" ";
}
}
fout<<"\n";
}
return 0;
}