This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
namespace
{
} // namespace
void solve()
{
int n, m, k;
cin >> n >> m >> k;
vector a(n, vector<array<long, 2>>(k));
for (int u = 0; u < n; u++)
{
for (auto &[x, y] : a[u])
cin >> x >> y;
}
vector<tuple<int, int, long>> edges(m);
for (auto &[u, v, w] : edges)
cin >> u >> v >> w, --u, --v;
vector dist(n, vector<long>(n, INT_MAX));
for (auto [u, v, w] : edges)
dist[u][v] = min(dist[u][v], w);
for (int s = 0; s < n; s++)
{
for (int u = 0; u < n; u++)
{
for (int v = 0; v < n; v++)
dist[u][v] = min(dist[u][v], dist[u][s] + dist[s][v]);
}
}
auto frac = [&](const array<long, 2> &lhs, const array<long, 2> &rhs) -> array<long, 2>
{ return {lhs[0] + rhs[0], lhs[1] + rhs[1]}; };
auto comp = [&](const array<long, 2> &lhs, const array<long, 2> &rhs) -> bool
{ return lhs[0] * rhs[1] < rhs[0] * lhs[1]; };
vector dp(n, vector<array<long, 2>>(n, {0, INT_MAX}));
for (int u = 0; u < n; u++)
{
for (int v = 0; v < n; v++)
{
long x = 0;
for (int i = 0; i < k; i++)
{
if (min(a[u][i][0], a[v][i][1]) != -1 && a[v][i][1] > a[u][i][0])
x = max(x, a[v][i][1] - a[u][i][0]);
}
dp[u][v] = {x, dist[u][v]};
}
}
for (int s = 0; s < n; s++)
{
for (int u = 0; u < n; u++)
{
for (int v = 0; v < n; v++)
{
if (max(dp[u][s][1], dp[s][v][1]) != INT_MAX)
dp[u][v] = max(dp[u][v], frac(dp[u][s], dp[s][v]), comp);
}
}
}
long res = 0;
for (int u = 0; u < n; u++)
res = max(res, dp[u][u][0] / dp[u][u][1]);
cout << res << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |