Pagini recente » Cod sursa (job #1755418) | Cod sursa (job #1812929) | Cod sursa (job #2485035) | Cod sursa (job #2108589) | Cod sursa (job #1983848)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int Nmax = 100 + 5;
const int INF = 0x3f3f3f3f;
int n;
int mat[Nmax][Nmax];
int main()
{
fin >> n;
for(int i = 1;i <= n; ++i)
for(int j = 1,x; 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(i!=j && mat[i][k] && mat[k][j])mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
for(int i = 1; i<= n; ++i,fout<<'\n')
for(int j = 1; j <= n; ++j)
fout<<mat[i][j]<<" ";
return 0;
}