# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52355 | imeimi2000 | Travelling Merchant (APIO17_merchant) | C++17 | 107 ms | 9544 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 <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int n, k;
const int inf = 1e9 + 7;
const llong linf = (llong)inf * inf;
int buy[101][1001], sell[101][1001];
int t[101][101];
int c[101][101];
llong d[101][101];
int main() {
int m;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
scanf("%d%d", buy[i] + j, sell[i] + j);
if (buy[i][j] != -1 && buy[i][j] < sell[i][j]) exit(1);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
t[i][j] = inf;
}
}
for (int i = 0; i < m; ++i) {
int v, w, p;
scanf("%d%d%d", &v, &w, &p);
t[v][w] = p;
}
for (int p = 1; p <= n; ++p) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
t[i][j] = min(t[i][j], t[i][p] + t[p][j]);
}
}
}
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= n; ++j) {
for (int p = 1; p <= n; ++p) {
if (buy[j][i] != -1 && sell[p][i] != -1) {
c[j][p] = max(c[j][p], sell[p][i] - buy[j][i]);
}
}
}
}
int s = 0, e = inf;
while (s < e) {
m = (s + e + 1) / 2;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (t[i][j] == inf) d[i][j] = linf;
else d[i][j] = (llong)m * t[i][j] - c[i][j];
}
}
for (int p = 1; p <= n; ++p) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
d[i][j] = min(d[i][j], d[i][p] + d[p][j]);
}
}
}
int ch = 0;
for (int i = 1; i <= n; ++i) {
if (d[i][i] <= 0) {
ch = 1;
break;
}
}
if (ch) s = m;
else e = m - 1;
}
printf("%d\n", s);
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... |