# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466340 | nonsensenonsense1 | Travelling Merchant (APIO17_merchant) | C++17 | 59 ms | 2240 KiB |
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 <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
const int N = 100;
const int K = 1000;
int n, m, k, dist[N][N], val[N][N], b[N][K][2];
long long to[N];
bool prev[N], cur[N];
bool test(int x)
{
memset(to, 0xcf, N << 3);
memset(cur, 0, N);
cur[0] = 1;
for (int i = 0; i <= n; ++i) {
std::swap(cur, prev);
memset(cur, 0, N);
for (int j = 0; j < n; ++j) if (prev[j]) for (int k = 0; k < n; ++k) {
long long d = to[j] + val[j][k] - (long long)dist[j][k] * x;
if (d >= to[k]) {
cur[k] = true;
to[k] = d;
}
}
}
for (int i = 0; i < 2 * n; ++i) if (cur[i]) return true;
return false;
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; ++i) for (int j = 0; j < k; ++j) scanf("%d%d", b[i][j], b[i][j] + 1);
memset(*dist, 0x3f, N * N << 2);
for (int i = 0; i < m; ++i) {
int v, w, t;
scanf("%d%d%d", &v, &w, &t);
dist[v - 1][w - 1] = t;
}
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k < n; ++k) dist[j][k] = std::min(dist[j][k], dist[j][i] + dist[i][k]);
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int l = 0; l < k; ++l) if (b[i][l][0] != -1 && b[j][l][1] != -1) val[i][j] = std::max(val[i][j], b[j][l][1] - b[i][l][0]);
int l = 0, r = 1000000000, ans = -1;
while (l <= r) {
int m = l + r >> 1;
if (test(m)) {
ans = m;
l = m + 1;
}
else r = m - 1;
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |