#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
const int MOD = 1e9+7;
#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
const int MXN = 1e5+5;
int n, m, k;
vector<pii> adj[MXN];
int order[MXN]; int counter = 0;
int H[MXN], lift[18][MXN];
int A[MXN];
vi ans;
void postorder(int u, int p) {
for(auto e : adj[u]) if(e.F != p) {
postorder(e.F, u);
}
order[u] = counter++;
}
void build_lift(int u, int p) {
H[u] = H[p]+1;
lift[0][u] = p;
for(auto e : adj[u]) if(e.F != p) {
build_lift(e.F, u);
}
}
int get_lca(int a, int b) {
if(H[a] < H[b]) swap(a, b);
// lift a to match b height
for(int p = 17; p >= 0; p--)
while(H[a]-(1<<p) >= H[b]) {
a = lift[p][a];
}
if(a == b) return a;
for(int p = 17; p >= 0; p--) {
while(lift[p][a] != lift[p][b]) {
a = lift[p][a];
b = lift[p][b];
}
}
return lift[0][a];
}
int dfs(int u, int p) {
int sum = A[u];
for(auto e : adj[u]) if(e.F != p) {
int subtree = dfs(e.F, u);
if(subtree >= k) {
ans.PB(e.S);
}
sum += subtree;
}
return sum;
}
int main() {
FASTIO();
cin >> n >> m >> k;
for(int i = 1; i < n; i++) {
int a, b; cin >> a >> b;
adj[a].PB({b, i});
adj[b].PB({a, i});
}
postorder(1, 1);
build_lift(1, 1);
for(int p = 1; p < 18; p++) {
for(int i = 1; i <= n; i++) {
lift[p][i] = lift[p-1][lift[p-1][i]];
}
}
for(int i = 0; i < m; i++) {
int sz; cin >> sz;
vi comp(sz);
for(int j = 0; j < sz; j++) cin >> comp[j];
sort(all(comp), [&](int a, int b) {
return order[a] < order[b];
});
for(int j = 0; j < sz; j++) A[comp[j]]++;
for(int j = 0; j < sz; j++) {
int lca = get_lca(comp[j], comp[(j+1)%sz]);
A[lca]--;
}
}
dfs(1, -1);
sort(all(ans));
cout << ans.size() << "\n";
for(int x : ans) cout << x << " ";
cout << "\n";
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
5 ms |
3980 KB |
Output is correct |
3 |
Correct |
7 ms |
4088 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
8 ms |
4620 KB |
Output is correct |
7 |
Correct |
6 ms |
4104 KB |
Output is correct |
8 |
Correct |
5 ms |
4052 KB |
Output is correct |
9 |
Correct |
6 ms |
4100 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
5 ms |
3980 KB |
Output is correct |
3 |
Correct |
7 ms |
4088 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
8 ms |
4620 KB |
Output is correct |
7 |
Correct |
6 ms |
4104 KB |
Output is correct |
8 |
Correct |
5 ms |
4052 KB |
Output is correct |
9 |
Correct |
6 ms |
4100 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
21 ms |
4436 KB |
Output is correct |
16 |
Correct |
20 ms |
4356 KB |
Output is correct |
17 |
Correct |
20 ms |
4436 KB |
Output is correct |
18 |
Correct |
6 ms |
4564 KB |
Output is correct |
19 |
Correct |
6 ms |
4076 KB |
Output is correct |
20 |
Correct |
19 ms |
4640 KB |
Output is correct |
21 |
Correct |
24 ms |
4516 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
6 ms |
3984 KB |
Output is correct |
24 |
Correct |
6 ms |
3976 KB |
Output is correct |
25 |
Correct |
2 ms |
2676 KB |
Output is correct |
26 |
Correct |
2 ms |
2772 KB |
Output is correct |
27 |
Correct |
8 ms |
4564 KB |
Output is correct |
28 |
Correct |
6 ms |
4180 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
5 ms |
4052 KB |
Output is correct |
31 |
Correct |
2 ms |
2772 KB |
Output is correct |
32 |
Correct |
2 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2772 KB |
Output is correct |
34 |
Correct |
2 ms |
2772 KB |
Output is correct |
35 |
Correct |
1 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
24192 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
83 ms |
25796 KB |
Output is correct |
4 |
Correct |
79 ms |
25220 KB |
Output is correct |
5 |
Correct |
85 ms |
26064 KB |
Output is correct |
6 |
Correct |
85 ms |
26412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
19024 KB |
Output is correct |
2 |
Correct |
82 ms |
16784 KB |
Output is correct |
3 |
Correct |
81 ms |
16380 KB |
Output is correct |
4 |
Correct |
73 ms |
16284 KB |
Output is correct |
5 |
Correct |
78 ms |
16360 KB |
Output is correct |
6 |
Correct |
58 ms |
20924 KB |
Output is correct |
7 |
Correct |
58 ms |
20812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
19024 KB |
Output is correct |
2 |
Correct |
82 ms |
16784 KB |
Output is correct |
3 |
Correct |
81 ms |
16380 KB |
Output is correct |
4 |
Correct |
73 ms |
16284 KB |
Output is correct |
5 |
Correct |
78 ms |
16360 KB |
Output is correct |
6 |
Correct |
58 ms |
20924 KB |
Output is correct |
7 |
Correct |
58 ms |
20812 KB |
Output is correct |
8 |
Correct |
66 ms |
21096 KB |
Output is correct |
9 |
Correct |
81 ms |
21180 KB |
Output is correct |
10 |
Correct |
71 ms |
26100 KB |
Output is correct |
11 |
Correct |
73 ms |
26080 KB |
Output is correct |
12 |
Correct |
56 ms |
16156 KB |
Output is correct |
13 |
Correct |
56 ms |
16120 KB |
Output is correct |
14 |
Correct |
76 ms |
16240 KB |
Output is correct |
15 |
Correct |
74 ms |
16268 KB |
Output is correct |
16 |
Correct |
76 ms |
16392 KB |
Output is correct |
17 |
Correct |
77 ms |
16392 KB |
Output is correct |
18 |
Correct |
84 ms |
16616 KB |
Output is correct |
19 |
Correct |
78 ms |
16756 KB |
Output is correct |
20 |
Correct |
77 ms |
21120 KB |
Output is correct |
21 |
Correct |
76 ms |
21252 KB |
Output is correct |
22 |
Correct |
64 ms |
21196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
5 ms |
3980 KB |
Output is correct |
3 |
Correct |
7 ms |
4088 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
8 ms |
4620 KB |
Output is correct |
7 |
Correct |
6 ms |
4104 KB |
Output is correct |
8 |
Correct |
5 ms |
4052 KB |
Output is correct |
9 |
Correct |
6 ms |
4100 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
21 ms |
4436 KB |
Output is correct |
16 |
Correct |
20 ms |
4356 KB |
Output is correct |
17 |
Correct |
20 ms |
4436 KB |
Output is correct |
18 |
Correct |
6 ms |
4564 KB |
Output is correct |
19 |
Correct |
6 ms |
4076 KB |
Output is correct |
20 |
Correct |
19 ms |
4640 KB |
Output is correct |
21 |
Correct |
24 ms |
4516 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
6 ms |
3984 KB |
Output is correct |
24 |
Correct |
6 ms |
3976 KB |
Output is correct |
25 |
Correct |
2 ms |
2676 KB |
Output is correct |
26 |
Correct |
2 ms |
2772 KB |
Output is correct |
27 |
Correct |
8 ms |
4564 KB |
Output is correct |
28 |
Correct |
6 ms |
4180 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
5 ms |
4052 KB |
Output is correct |
31 |
Correct |
2 ms |
2772 KB |
Output is correct |
32 |
Correct |
2 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2772 KB |
Output is correct |
34 |
Correct |
2 ms |
2772 KB |
Output is correct |
35 |
Correct |
1 ms |
2772 KB |
Output is correct |
36 |
Correct |
80 ms |
24192 KB |
Output is correct |
37 |
Correct |
1 ms |
2772 KB |
Output is correct |
38 |
Correct |
83 ms |
25796 KB |
Output is correct |
39 |
Correct |
79 ms |
25220 KB |
Output is correct |
40 |
Correct |
85 ms |
26064 KB |
Output is correct |
41 |
Correct |
85 ms |
26412 KB |
Output is correct |
42 |
Correct |
65 ms |
19024 KB |
Output is correct |
43 |
Correct |
82 ms |
16784 KB |
Output is correct |
44 |
Correct |
81 ms |
16380 KB |
Output is correct |
45 |
Correct |
73 ms |
16284 KB |
Output is correct |
46 |
Correct |
78 ms |
16360 KB |
Output is correct |
47 |
Correct |
58 ms |
20924 KB |
Output is correct |
48 |
Correct |
58 ms |
20812 KB |
Output is correct |
49 |
Correct |
66 ms |
21096 KB |
Output is correct |
50 |
Correct |
81 ms |
21180 KB |
Output is correct |
51 |
Correct |
71 ms |
26100 KB |
Output is correct |
52 |
Correct |
73 ms |
26080 KB |
Output is correct |
53 |
Correct |
56 ms |
16156 KB |
Output is correct |
54 |
Correct |
56 ms |
16120 KB |
Output is correct |
55 |
Correct |
76 ms |
16240 KB |
Output is correct |
56 |
Correct |
74 ms |
16268 KB |
Output is correct |
57 |
Correct |
76 ms |
16392 KB |
Output is correct |
58 |
Correct |
77 ms |
16392 KB |
Output is correct |
59 |
Correct |
84 ms |
16616 KB |
Output is correct |
60 |
Correct |
78 ms |
16756 KB |
Output is correct |
61 |
Correct |
77 ms |
21120 KB |
Output is correct |
62 |
Correct |
76 ms |
21252 KB |
Output is correct |
63 |
Correct |
64 ms |
21196 KB |
Output is correct |
64 |
Correct |
71 ms |
21232 KB |
Output is correct |
65 |
Correct |
96 ms |
16296 KB |
Output is correct |
66 |
Correct |
113 ms |
16340 KB |
Output is correct |
67 |
Correct |
112 ms |
16264 KB |
Output is correct |
68 |
Correct |
51 ms |
16076 KB |
Output is correct |
69 |
Correct |
45 ms |
16076 KB |
Output is correct |
70 |
Correct |
68 ms |
21556 KB |
Output is correct |
71 |
Correct |
77 ms |
20920 KB |
Output is correct |
72 |
Correct |
2 ms |
2772 KB |
Output is correct |
73 |
Correct |
6 ms |
4052 KB |
Output is correct |
74 |
Correct |
5 ms |
4052 KB |
Output is correct |
75 |
Correct |
2 ms |
2772 KB |
Output is correct |
76 |
Correct |
2 ms |
2772 KB |
Output is correct |
77 |
Correct |
6 ms |
4564 KB |
Output is correct |
78 |
Correct |
6 ms |
4100 KB |
Output is correct |
79 |
Correct |
5 ms |
4052 KB |
Output is correct |
80 |
Correct |
4 ms |
4052 KB |
Output is correct |
81 |
Correct |
2 ms |
2772 KB |
Output is correct |
82 |
Correct |
3 ms |
2772 KB |
Output is correct |
83 |
Correct |
2 ms |
2772 KB |
Output is correct |
84 |
Correct |
2 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
19 ms |
4360 KB |
Output is correct |
87 |
Correct |
19 ms |
4368 KB |
Output is correct |
88 |
Correct |
28 ms |
4500 KB |
Output is correct |
89 |
Correct |
7 ms |
4564 KB |
Output is correct |
90 |
Correct |
6 ms |
4180 KB |
Output is correct |
91 |
Correct |
20 ms |
4564 KB |
Output is correct |
92 |
Correct |
22 ms |
4516 KB |
Output is correct |
93 |
Correct |
3 ms |
2772 KB |
Output is correct |
94 |
Correct |
81 ms |
26104 KB |
Output is correct |
95 |
Correct |
87 ms |
25696 KB |
Output is correct |
96 |
Correct |
79 ms |
25208 KB |
Output is correct |
97 |
Correct |
82 ms |
26092 KB |
Output is correct |
98 |
Correct |
84 ms |
26480 KB |
Output is correct |
99 |
Correct |
86 ms |
16408 KB |
Output is correct |
100 |
Correct |
73 ms |
16396 KB |
Output is correct |
101 |
Correct |
84 ms |
16308 KB |
Output is correct |
102 |
Correct |
69 ms |
16844 KB |
Output is correct |
103 |
Correct |
68 ms |
21052 KB |
Output is correct |
104 |
Correct |
67 ms |
21248 KB |
Output is correct |
105 |
Correct |
78 ms |
20832 KB |
Output is correct |
106 |
Correct |
77 ms |
21232 KB |
Output is correct |
107 |
Correct |
74 ms |
21068 KB |
Output is correct |
108 |
Correct |
72 ms |
26096 KB |
Output is correct |
109 |
Correct |
70 ms |
26180 KB |
Output is correct |
110 |
Correct |
59 ms |
16120 KB |
Output is correct |
111 |
Correct |
59 ms |
16200 KB |
Output is correct |
112 |
Correct |
77 ms |
16328 KB |
Output is correct |
113 |
Correct |
81 ms |
16328 KB |
Output is correct |