이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 1e2 + 5;
constexpr ll Inf = 1e17;
ll w[N][N], b[N][N * 10], s[N][N * 10], d[N][N];
ll dp[N][N];
int n, m, k;
void Read()
{
cin >> n >> m >> k;
fill_n(&w[0][0], N * N, Inf);
for (int i = 1; i <= n; ++i)
{
w[i][i] = 0;
for (int j = 1; j <= k; ++j)
cin >> b[i][j] >> s[i][j];
}
for (int i = 1; i <= m; ++i)
{
int u, v;
cin >> u >> v;
cin >> w[u][v];
}
}
void Floyd()
{
for (int k = 1; k <= n; ++k)
for (int u = 1; u <= n; ++u)
for (int v = 1; v <= n; ++v)
w[u][v] = min(w[u][v], w[u][k] + w[k][v]);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
for (int t = 1; t <= k; ++t)
if (s[j][t] != -1 && b[i][t] != -1)
d[i][j] = max(d[i][j], s[j][t] - b[i][t]);
}
bool Check(ll v)
{
fill_n(&dp[0][0], N * N, Inf);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
dp[i][j] = v * min(w[i][j], Inf / v) - d[i][j];
for (int k = 1; k <= n; ++k)
for (int u = 1; u <= n; ++u)
for (int v = 1; v <= n; ++v)
dp[u][v] = max(-Inf, min(dp[u][v], dp[u][k] + dp[k][v]));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j && dp[i][j] < Inf && dp[j][i] < Inf && dp[i][j] + dp[j][i] <= 0)
return true;
return false;
}
void Solve()
{
Floyd();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j && w[i][j] < Inf && w[j][i] < Inf)
goto done;
cout << 0;
return;
done:;
ll l = 1, mid, h = Inf;
while (l <= h)
{
mid = (l + h) / 2;
if (Check(mid))
l = mid + 1;
else
h = mid - 1;
}
cout << h;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
}
# | 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... |