#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const ll INF = 1e18;
const int MAX_N = 3000;
vector<ii> adj[MAX_N];
void dfs(int u, vector<ll> &dist, int p = -1, ll d = 0) {
dist[u] = d;
for (auto [v, w] : adj[u]) {
if (v != p) dfs(v, dist, u, d + w);
}
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
for (int i = 0; i < N; i++) adj[i].clear();
for (int i = 0; i < N - 1; i++) {
adj[U[i]].emplace_back(V[i], W[i]);
adj[V[i]].emplace_back(U[i], W[i]);
}
vector<ll> distToX(N), distToY(N);
dfs(X, distToX), dfs(Y, distToY);
vector<ll> val[2], pref[2];
for (int i = 0; i < 2; i++) {
val[i].resize(N);
pref[i].assign(N + 1, 0);
}
for (int i = 0; i < N; i++) {
tie(val[0][i], val[1][i]) = minmax(distToX[i], distToY[i]);
val[1][i] -= val[0][i];
for (int j = 0; j < 2; j++) {
pref[j][i + 1] = pref[j][i] + val[j][i];
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = min(i, X); j < N; j++) {
for (int k = 0; k <= Y; k++) {
int l = Y - 1, r = N;
while (l + 1 < r) {
int m = (l + r) / 2;
ll sum;
if (j < k) {
sum = pref[0][m + 1] - pref[0][k] + pref[0][j + 1] - pref[0][i];
} else {
sum = pref[0][m + 1] - pref[0][min(i, k)] + pref[1][j + 1] - pref[1][max(k, i)];
}
if (sum <= K) l = m;
else r = m;
}
if (l != Y - 1) {
ans = max(ans, j - i + 1 + l - k + 1);
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
39 ms |
13472 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
504 KB |
1st lines differ - on the 1st token, expected: '30', found: '34' |
4 |
Halted |
0 ms |
0 KB |
- |