Pagini recente » Cod sursa (job #467876) | Cod sursa (job #1540252) | Cod sursa (job #1524446) | Cod sursa (job #55518) | Cod sursa (job #2581825)
#include <fstream>
#define inf 0x3f3f3f3f
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int nmax = 105;
int n;
int roy[nmax][nmax];
int main()
{
fin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
int c; fin >> c;
if(i == j)
roy[i][j] = 0;
else
{
if(c == 0)
{
roy[i][j] = inf;
}
else roy[i][j] = c;
}
}
}
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(roy[i][j] > roy[i][k] + roy[k][j])
roy[i][j] = roy[i][k] + roy[k][j];
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
fout << roy[i][j] << " ";
}
fout << "\n";
}
return 0;
}