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 int long long
using namespace std;
const long long INF = 1ll << 30;
const long long INF2 = 1ll << 60;
const int N = 100 + 5;
const int M = 1e4 + 5;
const int K = 1000 + 5;
int d[N][N], n, k, U[M], V[M], W[M], B[N][K], S[N][K], P[N][N], e, D[N][N];
void floyd(int d[N][N]) {
for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
bool check(int O) {
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = O * min(D[i][j], INF2 / O) - P[i][j];
floyd(d);
for (int i = 0; i < n; i++) if (d[i][i] <= 0) return true;
return false;
}
signed main() {
cin >> n >> e >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++)
cin >> B[i][j] >> S[i][j];
}
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) D[i][j] = INF2;
for (int i = 0; i < e; i++) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
D[u][v] = w;
}
floyd(D);
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int l = 0; l < k; l++) if (B[i][l] != -1 && S[j][l] != -1)
P[i][j] = max(P[i][j], -B[i][l] +S[j][l]);
int l = 0, r = INF;
while (r - l > 1) {
int m = l + r >> 1;
if (check(m)) l = m;
else r = m;
}
cout << l << endl;
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int main()':
merchant.cpp:42:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int m = l + r >> 1;
| ~~^~~
# | 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... |