Pagini recente » Cod sursa (job #121836) | Cod sursa (job #2850439) | Cod sursa (job #2468536) | Cod sursa (job #2564791) | Cod sursa (job #2971303)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int INF = 0x3f3f3f3f;
int n,mat[110][110];
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 && i!=j)
mat[i][j] = INF;
}
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';
}
return 0;
}