/* Ignut
started: 13.08.2024
now: 13.08.2024
████████████████████████████████████████████████████████████████████
████████████████████████████████ ████████████████████████████████
██████████████████████████████ ██████████████████████████████
██████ ██████████████████ ██████████████████ ██████
██████ ██████████████ ██████████████ ██████
██████ ██ ████████████ ████████████ ██ ██████
██████ ████ ██████████ ██████████ ████ ██████
██████ ████ ██████████ ██████████ ████ ██████
██████ ████ ██████████ ██████████ ██████ ██████
██████ ██████ ██████████ ██████████ ██████ ██████
██████ ██████ ████████ ████████ ██████ ██████
██████ ██████ ██████ ██████ ██████ ██████
██████ ████ ████ ████ ████ ██████
██████ ██████████ ████ ██████████ ██████
██████ ██ ██████ ████████ ██████ ██ ██████
██████ ██████ ████████ ██████ ██████
██████ ██ ██ ██████
██████████████████████ ████ ████ ██████████████████████
████████████████████████ ██ ██ ████████████████████████
██████████████████████████ ██████████████████████████
██████████████████████████████ ██████████████████████████████
████████████████████████████████████████████████████████████████████
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 2e5 + 123;
vector<pair<int, int>> tree[MAXN];
vector<int> order;
int pos[MAXN];
void dfs(int v, int par) {
order.push_back(v);
for (auto [to, w] : tree[v])
if (to != par)
dfs(to, v);
}
ll dx[MAXN], dy[MAXN];
void dfs2(int v, int par, ll d, bool f) {
if (f) dx[v] = d;
else dy[v] = d;
for (auto [to, w] : tree[v])
if (to != par)
dfs2(to, v, d + w, f);
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
order.clear();
for (int i = 0; i < N; i ++)
tree[i].clear();
for (int i = 0; i < N - 1; i ++) {
tree[U[i]].push_back({V[i], W[i]});
tree[V[i]].push_back({U[i], W[i]});
}
int start = 0;
for (int i = 0; i < N; i ++) {
if (tree[i].size() == 1) {
start = i; break;
}
}
dfs(start, -1);
for (int i = 0; i < N; i ++) pos[order[i]] = i;
dfs2(X, -1, 0, true);
dfs2(Y, -1, 0, false);
if (pos[X] > pos[Y]) {
swap(X, Y);
for (int i = 0; i < N; i ++) swap(dx[i], dy[i]);
}
int res = 0;
for (int l = 0; l < N; l ++) {
for (int r = l; r < N; r ++) {
ll sum = 0;
int ans = (r - l + 1) * 2;
for (int i = l; i <= r; i ++) sum += max(dx[order[i]], dy[order[i]]);
for (int i = pos[X]; i < l; i ++) sum += dx[order[i]], ans ++;
for (int i = pos[Y]; i > r; i --) sum += dy[order[i]], ans ++;
vector<ll> ds;
for (int i = 0; i < min(pos[X], l); i ++) ds.push_back(dx[order[i]]);
for (int i = max(pos[Y], r) + 1; i < N; i ++) ds.push_back(dy[order[i]]);
sort(ds.begin(), ds.end());
for (int i = 0; i < ds.size(); i ++) {
if (sum + ds[i] <= K) {
sum += ds[i];
ans ++;
}
}
if (sum <= K)
res = max(res, ans);
}
}
// no overlap
vector<ll> ds;
for (int i = 0; i < N; i ++) {
ds.push_back(dx[i]);
ds.push_back(dy[i]);
}
sort(ds.begin(), ds.end());
ll sum = 0;
int ans = 0;
for (int i = 0; i < ds.size(); i ++) {
if (sum + ds[i] <= K) {
sum += ds[i];
ans ++;
}
}
res = max(res, ans);
return res;
}
Compilation message
closing.cpp: In function 'int max_score(int, int, int, ll, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:95:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int i = 0; i < ds.size(); i ++) {
| ~~^~~~~~~~~~~
closing.cpp:115:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for (int i = 0; i < ds.size(); i ++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
27076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
1 ms |
8792 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
1 ms |
8792 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
3 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
4 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
330 ms |
8796 KB |
Output is correct |
20 |
Correct |
145 ms |
8796 KB |
Output is correct |
21 |
Correct |
164 ms |
9056 KB |
Output is correct |
22 |
Correct |
150 ms |
8796 KB |
Output is correct |
23 |
Correct |
30 ms |
8796 KB |
Output is correct |
24 |
Correct |
30 ms |
8948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
1 ms |
8792 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
3 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
4 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
330 ms |
8796 KB |
Output is correct |
20 |
Correct |
145 ms |
8796 KB |
Output is correct |
21 |
Correct |
164 ms |
9056 KB |
Output is correct |
22 |
Correct |
150 ms |
8796 KB |
Output is correct |
23 |
Correct |
30 ms |
8796 KB |
Output is correct |
24 |
Correct |
30 ms |
8948 KB |
Output is correct |
25 |
Correct |
19 ms |
8796 KB |
Output is correct |
26 |
Execution timed out |
1024 ms |
9048 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Incorrect |
1 ms |
8792 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8796 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Incorrect |
1 ms |
8792 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8796 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
8796 KB |
Output is correct |
20 |
Correct |
330 ms |
8796 KB |
Output is correct |
21 |
Correct |
145 ms |
8796 KB |
Output is correct |
22 |
Correct |
164 ms |
9056 KB |
Output is correct |
23 |
Correct |
150 ms |
8796 KB |
Output is correct |
24 |
Correct |
30 ms |
8796 KB |
Output is correct |
25 |
Correct |
30 ms |
8948 KB |
Output is correct |
26 |
Incorrect |
1 ms |
8792 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8796 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
8796 KB |
Output is correct |
20 |
Correct |
330 ms |
8796 KB |
Output is correct |
21 |
Correct |
145 ms |
8796 KB |
Output is correct |
22 |
Correct |
164 ms |
9056 KB |
Output is correct |
23 |
Correct |
150 ms |
8796 KB |
Output is correct |
24 |
Correct |
30 ms |
8796 KB |
Output is correct |
25 |
Correct |
30 ms |
8948 KB |
Output is correct |
26 |
Correct |
19 ms |
8796 KB |
Output is correct |
27 |
Execution timed out |
1024 ms |
9048 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8792 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8796 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8796 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
8796 KB |
Output is correct |
20 |
Correct |
330 ms |
8796 KB |
Output is correct |
21 |
Correct |
145 ms |
8796 KB |
Output is correct |
22 |
Correct |
164 ms |
9056 KB |
Output is correct |
23 |
Correct |
150 ms |
8796 KB |
Output is correct |
24 |
Correct |
30 ms |
8796 KB |
Output is correct |
25 |
Correct |
30 ms |
8948 KB |
Output is correct |
26 |
Correct |
19 ms |
8796 KB |
Output is correct |
27 |
Execution timed out |
1024 ms |
9048 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |