Pagini recente » Cod sursa (job #2974396) | Cod sursa (job #1644161) | Cod sursa (job #2415318) | Cod sursa (job #693482) | Cod sursa (job #2815465)
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
///Matricea drumurilor minime pentru orice pereche de noduri x, y
int n;
int mat[105][105];
int main()
{
fin>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++){
fin>>mat[i][j];
if(i!=j && mat[i][j]==0)
mat[i][j]=INT_MAX;
}
for(int k=1; k<=n; k++)
{
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
if(mat[i][k]+mat[k][j]<mat[i][j])
mat[i][j]=mat[i][k]+mat[k][j];
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++)
{
if(mat[i][j]==INT_MAX)
mat[i][j]=0;
fout<<mat[i][j]<<" ";
}
fout<<"\n";
}
return 0;
}