Pagini recente » Cod sursa (job #1565595) | Cod sursa (job #2549189) | Cod sursa (job #1879970) | Cod sursa (job #2230025) | Cod sursa (job #3192879)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,mat[105][105],matp[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(mat[i][j]==0)
{
mat[i][j]=1e9;
}
}
}
for(int k = 1 ; k <= n ; k ++)
{
for(int i = 1 ; i <= n ; i ++)
{
for(int j = 1 ; j <= n ; j ++)
{
if(i==j)
{
continue;
}
if(mat[i][j] > mat[i][k] + mat[k][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(i==j){fout<<0<<" ";continue;}
fout<<mat[i][j]<<" ";
}
fout<<'\n';
}
fin.close();
fout.close();
return 0;
}