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;
using ll = long long;
using pii = pair<int, int>;
#define ff first
#define ss second
int N, M, K;
int B[101][1000], S[101][1000], E[101][101], W[101][101];
bool f(ll m) {
ll X[101][101] = {0};
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) X[i][j] = -W[i][j] + m * E[i][j];
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) for (int k = 1; k <= N; ++k) {
if (j != k) X[j][k] = min(X[j][k], X[j][i] + X[i][k]);
}
for (int i = 1; i < N; ++i) for (int j = i + 1; j <= N; ++j) if (X[i][j] + X[j][i] <= 0) return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> M >> K;
for (int i = 1; i <= N; ++i) for (int j = 0; j < K; ++j) cin >> B[i][j] >> S[i][j];
for (int i = 0; i < M; ++i) {
int a, b, c; cin >> a >> b >> c;
E[a][b] = c;
}
for (int x = 1; x <= N; ++x) for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)
if (i != j && E[i][x] && E[x][j] && (!E[i][j] || E[i][j] > E[i][x] + E[x][j])) E[i][j] = E[i][x] + E[x][j];
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) for (int k = 0; k < K; ++k)
if(S[j][k] > 0 && B[i][k] > 0) W[i][j] = max(W[i][j], S[j][k] - B[i][k]);
ll l = 0, r = 1e12;
while (l < r) {
ll m = l + r + 1 >> 1;
if (f(m)) l = m;
else r = m - 1;
}
cout << r;
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int main()':
merchant.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m = l + r + 1 >> 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... |