#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int P[505][505];
int32_t main() {
int n, m, K;
cin >> n >> m >> K;
vector<vector<ll> > M(n+1, vector<ll>(n+1, 1e16));
int B[n+1][K], S[n+1][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;
M[a][b] = min(M[a][b], 1ll * c);
}
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) M[i][j] = min(M[i][j], M[i][k] + M[k][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] != -1 && B[i][k] != -1) P[i][j] = max(P[i][j], S[j][k] - B[i][k]);
ll l=1, r=1e6, ans=0;
while(l <= r) {
ll mid = (l + r) / 2;
vector<vector<ll> > M2(n+1, vector<ll>(n+1, 1e16));
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) M2[i][j] = mid * M[i][j] - P[i][j];
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) M2[i][j] = min(M2[i][j], M2[i][k] + M2[k][j]);
bool ok = 0;
for(int i=1; i<=n; i++)
if(M2[i][i] <= 0) ok = 1;
if(ok) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
2384 KB |
Output is correct |
2 |
Correct |
17 ms |
604 KB |
Output is correct |
3 |
Incorrect |
19 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
580 KB |
Output is correct |
2 |
Incorrect |
3 ms |
440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
856 KB |
Output is correct |
2 |
Incorrect |
78 ms |
3120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
580 KB |
Output is correct |
2 |
Incorrect |
3 ms |
440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |