# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117459 | thtsshz_bgwrswh | Travelling Merchant (APIO17_merchant) | C++17 | 54 ms | 4188 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 <stdio.h>
#include <algorithm>
using namespace std;
const long long INF = 1e18;
long long buy[105][1005], sell[105][1005];
long long graph[105][105], profit[105][105];
long long graph2[105][105];
long long n, m, x;
void floyd(long long graph[105][105]) {
for (long long k = 1; k <= n; k++)
for (long long i = 1; i <= n; i++)
for (long long j = 1; j <= n; j++)
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
int main() {
scanf("%lld %lld %lld", &n, &m, &x);
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= n; j++) graph[i][j] = INF;
for (long long j = 1; j <= x; j++) {
scanf("%lld %lld", &buy[i][j], &sell[i][j]);
}
}
for (long long i = 0; i < m; i++) {
long long u, v, c;
scanf("%lld %lld %lld", &u, &v, &c);
graph[u][v] = c;
}
floyd(graph);
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= n; j++) {
for (long long l = 1; l <= x; l++) {
if (sell[j][l] != -1 && buy[i][l] != -1)
profit[i][j] = max(profit[i][j], sell[j][l] - buy[i][l]);
}
}
}
long long left = 1, right = 1e9;
while (left <= right) {
long long mid = (left + right) / 2;
for (long long i = 1; i <= n; i++)
for (long long j = 1; j <= n; j++)
graph2[i][j] = mid * min(graph[i][j], INF / mid) - profit[i][j];
floyd(graph2);
bool has_nonnegative_cycle = false;
for (long long i = 1; i <= n; i++)
if (graph2[i][i] <= 0) has_nonnegative_cycle = true;
if (has_nonnegative_cycle)
left = mid + 1;
else
right = mid - 1;
}
printf("%lld\n", right);
}
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... |