Pagini recente » Cod sursa (job #2124489) | Cod sursa (job #352138) | Cod sursa (job #1463383) | Cod sursa (job #1882117) | Cod sursa (job #3192869)
/******************************************************************************
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];
}
}
for(int k = 1 ; k <= n ; k ++)
{
for(int i = 1 ; i <= n ; i ++)
{
for(int j = 1 ; j <= n ; j ++)
{
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++)
{
fout<<mat[i][j]<<" ";
}
fout<<'\n';
}
fin.close();
fout.close();
return 0;
}