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 int long long
const int N = 101;
const int K = 1001;
const int INF = 1e18;
int n, m, k;
int dist[N][N], p[N][N], buy[N][K], sell[N][K];
bool check(int k) {
vector<vector<int>> d(N, vector<int> (N, INF));
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
if (j != i && dist[i][j] != INF) {
d[i][j] = k * min(dist[i][j], INF / k) - p[i][j];
}
}
for (int x = 1; x <= n; x++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
if (d[i][x] < INF && d[x][j] < INF) d[i][j] = min(d[i][j], max(-INF, d[i][x] + d[x][j]));
}
for (int x = 1; x <= n; x++) if (d[x][x] <= 0) return true;
return false;
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) cin >> buy[i][j] >> sell[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
for (int id = 1; id <= k; id++) {
if (sell[j][id] == -1 || buy[i][id] == -1) continue;
p[i][j] = max(p[i][j], sell[j][id] - buy[i][id]);
}
}
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) dist[i][j] = INF;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
dist[u][v] = min(dist[u][v], w);
}
for (int x = 1; x <= n; x++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]);
int lb = 0, rb = INF;
while (lb < rb) {
int mid = (lb + rb + 1) / 2;
if (check(mid)) lb = mid;
else rb = mid - 1;
}
cout << lb << '\n';
}
# | 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... |