Pagini recente » Cod sursa (job #354754) | Cod sursa (job #2698646) | Cod sursa (job #3291597) | Cod sursa (job #2958379) | Cod sursa (job #3260017)
//https://infoarena.ro/problema/royfloyd
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("fast-math")
//#pragma GCC optimize ("unroll-loops")
//#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
//#include <algorithm>
//#include <cmath>
#include <vector>
#include <queue>
#include <utility>
//#include <bitset>
//#include <iomanip>
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
int d[105][105];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i, j, k, x;
fin >> n;
for (i = 1; i <= n; ++i)
{
for (j = 1; j <= n; ++j)
{
fin >> x;
d[i][j] = x;
if (i != j && d[i][j] == 0)
d[i][j] = 1e6;
}
}
for (k = 1; k <= n; ++k)
{
for (i = 1; i <= n; ++i)
{
for (j = 1; j <= n; ++j)
{
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for (i = 1; i <= n; ++i)
{
for (j = 1; j <= n; ++j)
{
if (d[i][j] == 1e6)
fout << "0 ";
else
fout << d[i][j] << " ";
}
fout << "\n";
}
return 0;
}