# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
551462 | Ai7081 | Travelling Merchant (APIO17_merchant) | C++17 | 70 ms | 2040 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>
using namespace std;
#define long long long
const int N = 105;
const int I = 1005;
const long inf = 1e18;
long n, m, item, x, y, z, dis[N][N], fin[N][N], val[N][N], b[N][I], s[N][I];
int main() {
scanf(" %lld %lld %lld", &n, &m, &item);
for (int i=1; i<=n; i++) {
for (int j=1; j<=item; j++) scanf(" %lld", &b[i][j]);
for (int j=1; j<=item; j++) scanf(" %lld", &s[i][j]);
}
fill_n(dis[0], N*N, inf);
while (m--) {
scanf(" %lld %lld %lld", &x, &y, &z);
dis[x][y] = z;
}
for (int k=1; k<=n; k++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) {
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) for (int k=1; k<=item; k++) {
if (b[i][k]!=-1 && s[j][k]!=-1) val[i][j] = max(val[i][j], s[j][k] - b[i][k]);
}
// for (int i=1; i<=n; i++) {for (int j=1; j<=n; j++) printf("%lld " , dis[i][j]); printf("\n");}
// for (int i=1; i<=n; i++) {for (int j=1; j<=n; j++) printf("%lld " , val[i][j]); printf("\n");}
long l=1, r=1e9;
while (l <= r) {
long mid = (l+r)>>1;
// printf("%lld %lld %lld\n", l, mid, r);
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) fin[i][j] = mid * min(dis[i][j], inf/mid) - val[i][j];
for (int k=1; k<=n; k++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) {
fin[i][j] = min(fin[i][j], fin[i][k] + fin[k][j]);
}
bool ok = false;
for (int i=1; i<=n; i++) if (fin[i][i] <= 0) {ok=true; break;}
if (ok) l = mid+1;
else r = mid-1;
}
printf("%lld", r);
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... |