# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373657 | abra_stone | Travelling Merchant (APIO17_merchant) | C++14 | 185 ms | 2440 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 <iostream>
#include <cstdio>
#define N 105
#define K 1005
using namespace std;
typedef long long ll;
ll n, eg, m, b[N][K], s[N][K], d[N][N], mx[N][N], mn[N][N];
bool f(ll p) {
ll i, j, k;
for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) mn[i][j] = p * d[i][j] - mx[i][j];
for (k = 1; k <= n; k++) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (mn[i][k] + mn[k][j] < mn[i][j]) mn[i][j] = mn[i][k] + mn[k][j];
}
}
}
for (i = 1; i <= n; i++) if (mn[i][i] <= 0) return 1;
return 0;
}
int main()
{
ll i, j, k, t1, t2, t3;
cin >> n >> eg >> m;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
scanf("%lld %lld", &b[i][j], &s[i][j]);
// if (b[i][j] == -1) b[i][j] = 1e18;
// if (s[i][j] == -1) s[i][j] = -1e18;
}
}
for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) d[i][j] = 3e7;
while (eg--) {
scanf("%lld %lld %lld", &t1, &t2, &t3);
d[t1][t2] = t3;
}
for (k = 1; k <= n; k++) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
for (k = 1; k <= m; k++) {
if (s[j][k] != -1 && b[i][k] != -1) mx[i][j] = max(mx[i][j], s[j][k] - b[i][k]);
}
}
}
ll l = 1, r = 1e11;
while (l < r) {
ll md = (l + r + 1) / 2;
if (f(md)) l = md;
else r = md - 1;
}
cout << l << endl;
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... |