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, K = 1001, inf = 2e9;
int cost[N][N], d[N][N], dis[N][N], B[N][K], S[N][K], n;
bool check(int x) {
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[i][j] = dis[i][j] * x - cost[i][j];
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) if (i != j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j && d[i][j] + d[j][i] <= 0) return 1;
return 0;
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int m, k; cin >> n >> m >> k;
for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) cin >> B[i][j] >> S[i][j];
for (int u = 1; u <= n; u++)
for (int v = 1; v <= n; v++)
for (int i = 1; i <= k; i++) if (B[u][i] != -1 && S[v][i] != -1)
cost[u][v] = max(cost[u][v], S[v][i] - B[u][i]);
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) dis[i][j] = inf;
for (int i = 0; i < m; i++) {int u, v, w; cin >> u >> v >> w, dis[u][v] = min(dis[u][v], w);}
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]);
int dw = 0, up = inf;
while (up - dw > 1) {
int md = (up+dw)>>1;
if (check(md)) dw = md;
else up = md;
}
cout << dw << "\n";
return 0;
}
# | 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... |