Pagini recente » Monitorul de evaluare | Cod sursa (job #2735218)
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pd = pair<double, double>;
using pld = pair<ld, ld>;
int main()
{
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int N;
cin >> N;
vector<vector<int>> shortest_dist(N + 1, vector<int>(N + 1));
for (int i = 1; i <= N; ++i)
{
for (int j = 1; j <= N; ++j)
{
cin >> shortest_dist[i][j];
if (shortest_dist[i][j] == 0)
{
shortest_dist[i][j] = 1e9;
}
}
}
auto Roy_Floyd = [&]() -> void
{
for (int k = 1; k <= N; ++k)
{
shortest_dist[k][k] = 0;
for (int i = 1; i <= N; ++i)
{
for (int j = 1; j <= N; ++j)
{
shortest_dist[i][j] = min(shortest_dist[i][j], shortest_dist[i][k] + shortest_dist[k][j]);
}
}
}
};
Roy_Floyd();
for (int i = 1; i <= N; ++i)
{
for (int j = 1; j <= N; ++j)
{
cout << (shortest_dist[i][j] == 1e9 ? 0 : shortest_dist[i][j]) << " \n"[j == N];
}
}
}