# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
906105 | nguyentunglam | Travelling Merchant (APIO17_merchant) | C++17 | 98 ms | 3624 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<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int N = 110, M = 1e3 + 10;
int n, m, K;
int x[N * N], y[N * N], z[N * N];
long long f[N][N], g[N][N];
int cost[N][N];
int s[N][M], b[N][M];
int32_t main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
if (fopen(task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n >> m >> K;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= K; j++) cin >> b[i][j] >> s[i][j];
}
for(int i = 1; i <= m; i++) cin >> x[i] >> y[i] >> z[i];
auto calc = [&] (int mid) {
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) f[i][j] = 1e16;
for(int i = 1; i <= n; i++) f[i][i] = 0;
for(int i = 1; i <= m; i++) f[x[i]][y[i]] = min(f[x[i]][y[i]], 1LL * z[i] * mid);
for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
}
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
g[i][j] = cost[i][j] - f[i][j];
if (i == j) g[i][j] = -1e16;
}
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
// cout << i << " " << j << " " << g[i][j] << " " << f[i][j] << " " << cost[i][j] << endl;
}
for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
g[i][j] = max(g[i][j], g[i][k] + g[k][j]);
}
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
// cout << i << " " << j << " " << g[i][j] << endl;
}
for(int i = 1; i <= n; i++) if (g[i][i] >= 0) return true;
return false;
};
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
for(int k = 1; k <= K; k++) if (s[j][k] != -1 && b[i][k] != -1) {
cost[i][j] = max(cost[i][j], s[j][k] - b[i][k]);
}
}
// cout << calc(2);return 0;
int l = 1, r = 1e9, ans = 0;
while (l <= r) {
int mid = l + r >> 1;
if (calc(mid)) {
ans = mid;
l = mid + 1;
} else r = mid - 1;
}
cout << ans;
}
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... |