#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 101, K = 1001, inf = 1e16;
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++) if (i != 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] = 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 |
1 |
Incorrect |
102 ms |
2040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
896 KB |
Output is correct |
2 |
Correct |
14 ms |
896 KB |
Output is correct |
3 |
Correct |
20 ms |
964 KB |
Output is correct |
4 |
Correct |
15 ms |
896 KB |
Output is correct |
5 |
Correct |
15 ms |
896 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Incorrect |
14 ms |
896 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
1536 KB |
Output is correct |
2 |
Incorrect |
129 ms |
2168 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
896 KB |
Output is correct |
2 |
Correct |
14 ms |
896 KB |
Output is correct |
3 |
Correct |
20 ms |
964 KB |
Output is correct |
4 |
Correct |
15 ms |
896 KB |
Output is correct |
5 |
Correct |
15 ms |
896 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Incorrect |
14 ms |
896 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |