Pagini recente » Cod sursa (job #2252587) | Profil Djok | Cod sursa (job #1548904) | Rating Nume complet (nevrax) | Cod sursa (job #2301658)
#include <bits/stdc++.h>
#define nmax 100050
using namespace std;
vector <int> g[nmax], viz;
int n, dist[100][100];
void citire()
{
ifstream fin("royfloyd.in");
int x;
fin >> n;
viz.push_back(0);
for (int i = 1; i <= n; i++)
{
g[i].push_back(0);
for (int j = 1; j <= n; j++)
{
fin >> x;
g[i].push_back(x);
}
}
}
void royfloyd()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
dist[i][j] = g[i][j];
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (dist[i][j] > dist[i][k] + dist[k][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
void tipar()
{
ofstream fout("royfloyd.out");
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
fout << dist[i][j] << " ";
fout << "\n";
}
}
int main()
{
citire();
royfloyd();
tipar();
return 0;
}