#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn = 1e5 + 1, maxLg = 20;
int n, q, k, timer, a[maxn], h[maxn], st[maxn], fn[maxn], par[maxn][maxLg];
vector <pair <int, int>> adj[maxn], check;
vector <int> res;
void dfs (int v, int p = 0){
st[v] = timer++;
par[v][0] = p;
for (int i = 1; i < maxLg; i++)
par[v][i] = par[par[v][i - 1]][i - 1];
for (auto [u, ind] : adj[v]){
if (u != p){
h[u] = h[v] + 1;
dfs(u, v);
}
}
fn[v] = timer++;
}
int lca (int x, int y){
if (h[x] < h[y])
swap(x, y);
if (st[x] <= st[y] && fn[x] >= fn[y])
return x;
for (int i = maxLg - 1; i >= 0; i--){
if (par[x][i] == 0)
continue;
int u = par[x][i];
if (!(st[u] <= st[y] && fn[u] >= fn[y]))
x = u;
}
return par[x][0];
}
void dfs2 (int v, int ind, int p = 0){
for (auto [u, i] : adj[v])
if (u != p)
dfs2(u, i, v);
a[p] += a[v];
if (a[v] >= 2 * k && ind > -1)
res.pb(ind);
}
int main (){
ios_base::sync_with_stdio(0);
cin >> n >> q >> k;
for (int x, y, i = 0; i < n - 1; i++)
cin >> x >> y,
adj[x].pb({y, i}),
adj[y].pb({x, i});
dfs(1);
for (int s, i = 0; i < q; i++){
cin >> s;
for (int x, j = 0; j < s; j++)
cin >> x,
check.pb({st[x], x});
sort(check.begin(), check.end());
for (int j = 0; j < s; j++){
auto [v, u] = make_pair(check[j].second, check[(j + 1) % s].second);
a[v]++;
a[u]++;
a[lca(v, u)] -= 2;
}
check.clear();
}
dfs2(1, -1);
sort(res.begin(), res.end());
cout << res.size() << '\n';
for (auto e : res)
cout << e + 1 << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
4188 KB |
Output is correct |
3 |
Correct |
4 ms |
4136 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
4444 KB |
Output is correct |
7 |
Correct |
6 ms |
4188 KB |
Output is correct |
8 |
Correct |
4 ms |
4108 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2592 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
4188 KB |
Output is correct |
3 |
Correct |
4 ms |
4136 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
4444 KB |
Output is correct |
7 |
Correct |
6 ms |
4188 KB |
Output is correct |
8 |
Correct |
4 ms |
4108 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2592 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
14 ms |
4444 KB |
Output is correct |
16 |
Correct |
13 ms |
4516 KB |
Output is correct |
17 |
Correct |
14 ms |
4604 KB |
Output is correct |
18 |
Correct |
5 ms |
4444 KB |
Output is correct |
19 |
Correct |
5 ms |
4204 KB |
Output is correct |
20 |
Correct |
11 ms |
4688 KB |
Output is correct |
21 |
Correct |
13 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
4 ms |
4188 KB |
Output is correct |
24 |
Correct |
4 ms |
4120 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
5 ms |
4444 KB |
Output is correct |
28 |
Correct |
4 ms |
4188 KB |
Output is correct |
29 |
Correct |
3 ms |
4188 KB |
Output is correct |
30 |
Correct |
4 ms |
4188 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2816 KB |
Output is correct |
33 |
Correct |
1 ms |
2908 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
24232 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
68 ms |
23760 KB |
Output is correct |
4 |
Correct |
65 ms |
23360 KB |
Output is correct |
5 |
Correct |
77 ms |
24184 KB |
Output is correct |
6 |
Correct |
68 ms |
24444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
20656 KB |
Output is correct |
2 |
Correct |
52 ms |
17900 KB |
Output is correct |
3 |
Correct |
48 ms |
17564 KB |
Output is correct |
4 |
Correct |
46 ms |
17712 KB |
Output is correct |
5 |
Correct |
52 ms |
17488 KB |
Output is correct |
6 |
Correct |
53 ms |
20820 KB |
Output is correct |
7 |
Correct |
52 ms |
20564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
20656 KB |
Output is correct |
2 |
Correct |
52 ms |
17900 KB |
Output is correct |
3 |
Correct |
48 ms |
17564 KB |
Output is correct |
4 |
Correct |
46 ms |
17712 KB |
Output is correct |
5 |
Correct |
52 ms |
17488 KB |
Output is correct |
6 |
Correct |
53 ms |
20820 KB |
Output is correct |
7 |
Correct |
52 ms |
20564 KB |
Output is correct |
8 |
Correct |
54 ms |
20820 KB |
Output is correct |
9 |
Correct |
60 ms |
20852 KB |
Output is correct |
10 |
Correct |
71 ms |
24184 KB |
Output is correct |
11 |
Correct |
65 ms |
24268 KB |
Output is correct |
12 |
Correct |
39 ms |
17416 KB |
Output is correct |
13 |
Correct |
46 ms |
17488 KB |
Output is correct |
14 |
Correct |
45 ms |
17492 KB |
Output is correct |
15 |
Correct |
48 ms |
17488 KB |
Output is correct |
16 |
Correct |
46 ms |
17488 KB |
Output is correct |
17 |
Correct |
44 ms |
17488 KB |
Output is correct |
18 |
Correct |
46 ms |
17492 KB |
Output is correct |
19 |
Correct |
53 ms |
18004 KB |
Output is correct |
20 |
Correct |
50 ms |
21076 KB |
Output is correct |
21 |
Correct |
53 ms |
21020 KB |
Output is correct |
22 |
Correct |
54 ms |
21072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
4188 KB |
Output is correct |
3 |
Correct |
4 ms |
4136 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
4444 KB |
Output is correct |
7 |
Correct |
6 ms |
4188 KB |
Output is correct |
8 |
Correct |
4 ms |
4108 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2592 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
14 ms |
4444 KB |
Output is correct |
16 |
Correct |
13 ms |
4516 KB |
Output is correct |
17 |
Correct |
14 ms |
4604 KB |
Output is correct |
18 |
Correct |
5 ms |
4444 KB |
Output is correct |
19 |
Correct |
5 ms |
4204 KB |
Output is correct |
20 |
Correct |
11 ms |
4688 KB |
Output is correct |
21 |
Correct |
13 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
4 ms |
4188 KB |
Output is correct |
24 |
Correct |
4 ms |
4120 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
5 ms |
4444 KB |
Output is correct |
28 |
Correct |
4 ms |
4188 KB |
Output is correct |
29 |
Correct |
3 ms |
4188 KB |
Output is correct |
30 |
Correct |
4 ms |
4188 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2816 KB |
Output is correct |
33 |
Correct |
1 ms |
2908 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
76 ms |
24232 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
68 ms |
23760 KB |
Output is correct |
39 |
Correct |
65 ms |
23360 KB |
Output is correct |
40 |
Correct |
77 ms |
24184 KB |
Output is correct |
41 |
Correct |
68 ms |
24444 KB |
Output is correct |
42 |
Correct |
48 ms |
20656 KB |
Output is correct |
43 |
Correct |
52 ms |
17900 KB |
Output is correct |
44 |
Correct |
48 ms |
17564 KB |
Output is correct |
45 |
Correct |
46 ms |
17712 KB |
Output is correct |
46 |
Correct |
52 ms |
17488 KB |
Output is correct |
47 |
Correct |
53 ms |
20820 KB |
Output is correct |
48 |
Correct |
52 ms |
20564 KB |
Output is correct |
49 |
Correct |
54 ms |
20820 KB |
Output is correct |
50 |
Correct |
60 ms |
20852 KB |
Output is correct |
51 |
Correct |
71 ms |
24184 KB |
Output is correct |
52 |
Correct |
65 ms |
24268 KB |
Output is correct |
53 |
Correct |
39 ms |
17416 KB |
Output is correct |
54 |
Correct |
46 ms |
17488 KB |
Output is correct |
55 |
Correct |
45 ms |
17492 KB |
Output is correct |
56 |
Correct |
48 ms |
17488 KB |
Output is correct |
57 |
Correct |
46 ms |
17488 KB |
Output is correct |
58 |
Correct |
44 ms |
17488 KB |
Output is correct |
59 |
Correct |
46 ms |
17492 KB |
Output is correct |
60 |
Correct |
53 ms |
18004 KB |
Output is correct |
61 |
Correct |
50 ms |
21076 KB |
Output is correct |
62 |
Correct |
53 ms |
21020 KB |
Output is correct |
63 |
Correct |
54 ms |
21072 KB |
Output is correct |
64 |
Correct |
57 ms |
20816 KB |
Output is correct |
65 |
Correct |
47 ms |
17488 KB |
Output is correct |
66 |
Correct |
50 ms |
17524 KB |
Output is correct |
67 |
Correct |
52 ms |
17752 KB |
Output is correct |
68 |
Correct |
41 ms |
17172 KB |
Output is correct |
69 |
Correct |
34 ms |
17240 KB |
Output is correct |
70 |
Correct |
54 ms |
21328 KB |
Output is correct |
71 |
Correct |
55 ms |
20564 KB |
Output is correct |
72 |
Correct |
1 ms |
2648 KB |
Output is correct |
73 |
Correct |
4 ms |
4188 KB |
Output is correct |
74 |
Correct |
4 ms |
4188 KB |
Output is correct |
75 |
Correct |
1 ms |
2652 KB |
Output is correct |
76 |
Correct |
2 ms |
2652 KB |
Output is correct |
77 |
Correct |
4 ms |
4524 KB |
Output is correct |
78 |
Correct |
4 ms |
4188 KB |
Output is correct |
79 |
Correct |
4 ms |
4188 KB |
Output is correct |
80 |
Correct |
4 ms |
4188 KB |
Output is correct |
81 |
Correct |
1 ms |
2652 KB |
Output is correct |
82 |
Correct |
1 ms |
2652 KB |
Output is correct |
83 |
Correct |
1 ms |
2652 KB |
Output is correct |
84 |
Correct |
1 ms |
2652 KB |
Output is correct |
85 |
Correct |
1 ms |
2648 KB |
Output is correct |
86 |
Correct |
13 ms |
4612 KB |
Output is correct |
87 |
Correct |
13 ms |
4444 KB |
Output is correct |
88 |
Correct |
14 ms |
4700 KB |
Output is correct |
89 |
Correct |
5 ms |
4444 KB |
Output is correct |
90 |
Correct |
5 ms |
4164 KB |
Output is correct |
91 |
Correct |
12 ms |
4808 KB |
Output is correct |
92 |
Correct |
16 ms |
4696 KB |
Output is correct |
93 |
Correct |
1 ms |
2652 KB |
Output is correct |
94 |
Correct |
90 ms |
24148 KB |
Output is correct |
95 |
Correct |
67 ms |
23760 KB |
Output is correct |
96 |
Correct |
65 ms |
23216 KB |
Output is correct |
97 |
Correct |
75 ms |
24264 KB |
Output is correct |
98 |
Correct |
81 ms |
24524 KB |
Output is correct |
99 |
Correct |
46 ms |
17500 KB |
Output is correct |
100 |
Correct |
46 ms |
17716 KB |
Output is correct |
101 |
Correct |
53 ms |
17500 KB |
Output is correct |
102 |
Correct |
46 ms |
17996 KB |
Output is correct |
103 |
Correct |
51 ms |
20816 KB |
Output is correct |
104 |
Correct |
49 ms |
21076 KB |
Output is correct |
105 |
Correct |
49 ms |
20692 KB |
Output is correct |
106 |
Correct |
63 ms |
20816 KB |
Output is correct |
107 |
Correct |
53 ms |
20820 KB |
Output is correct |
108 |
Correct |
66 ms |
24316 KB |
Output is correct |
109 |
Correct |
68 ms |
24268 KB |
Output is correct |
110 |
Correct |
39 ms |
17496 KB |
Output is correct |
111 |
Correct |
36 ms |
17288 KB |
Output is correct |
112 |
Correct |
44 ms |
17448 KB |
Output is correct |
113 |
Correct |
45 ms |
17492 KB |
Output is correct |