Pagini recente » Cod sursa (job #2154448) | Cod sursa (job #1645235) | Cod sursa (job #2224223) | Istoria paginii runda/concurs7_1/clasament | Cod sursa (job #2967524)
#include <fstream>
#include <climits>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <bitset>
#include <map>
#include <cstring>
#include <algorithm>
#define NMAX 103
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int mat[NMAX][NMAX];
long long dist[NMAX][NMAX];
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
fin >> mat[i][j];
dist[i][j] = mat[i][j];
if (mat[i][j] == 0)
{
dist[i][j] = INT_MAX;
}
}
dist[i][i] = 0;
}
for (int aux = 1; aux <= n; aux++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (dist[i][aux]!=INT_MAX && dist[aux][j]!=INT_MAX && dist[i][j] >= dist[i][aux] + dist[aux][j])
{
dist[i][j] = dist[i][aux] + dist[aux][j];
}
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (dist[i][j] == INT_MAX)
{
fout << "0 ";
}
else {
fout << dist[i][j] << " ";
}
}
fout << "\n";
}
return 0;
}