#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
cin.tie(NULL),cin.sync_with_stdio(false);
int n,m,k; cin >> n >> m >> k;
int B = __lg(n+1)+2;
vector<vector<array<int,2>>> adj(n);
vvi par(B+1, vi(n));
vi d(n), ord(n), cnt(n), vis(n), E(n);
int cc = 0;
auto dfs = [&](int at, int dep, auto&& dfs) -> void {
ord[at] = cc++;
vis[at] = 1;
d[at] = dep;
for(auto [to,id] : adj[at]) if (!vis[to]){
par[0][to] = at;
E[to] = id;
dfs(to,dep+1,dfs);
}
};
rep(i,0,n-1){
int u,v; cin >> u >> v;
u--,v--;
adj[u].push_back({v,i+1});
adj[v].push_back({u,i+1});
}
dfs(0,0,dfs);
rep(i,0,B) rep(j,0,n) par[i+1][j] = par[i][par[i][j]];
auto jmp = [&](int at, int k) -> int {
for(int i = 0; k; ++i, k/=2)
if(k&1) at = par[i][at];
return at;
};
auto lca = [&](int u, int v) -> int {
if (d[u] < d[v]) swap(u,v);
u = jmp(u,d[u]-d[v]);
if (u==v) return u;
for(int i = B; i>=0; --i)
if (par[i][u] != par[i][v])
u = par[i][u], v = par[i][v];
return par[0][u];
};
while (m--){
int t; cin >> t;
vi a(t);
rep(i,0,t) cin >> a[i], a[i]--;
sort(all(a),[&](int u, int v){
return ord[u] < ord[v];
});
int last = a[t-1];
for(auto cur : a){
cnt[cur]++;
cnt[last]++;
cnt[lca(cur,last)]-=2;
last = cur;
}
}
fill(all(vis),0);
auto prop = [&](int at, auto&& prop) -> void {
vis[at] = 1;
for(auto [to,id] : adj[at]) if (!vis[to]){
prop(to,prop);
cnt[at] += cnt[to];
}
};
prop(0,prop);
vi ans;
rep(i,0,n) if (cnt[i] >= 2*k) ans.push_back(E[i]);
sort(all(ans));
cout << sz(ans) << '\n';
for(auto c : ans) cout << c << ' ';
cout << '\n';
}
/*
10 3 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 9
9 10
5 2 5 4 6 8
6 1 3 5 6 4 10
3 1 5 7
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
2136 KB |
Output is correct |
7 |
Correct |
4 ms |
1884 KB |
Output is correct |
8 |
Correct |
3 ms |
1884 KB |
Output is correct |
9 |
Correct |
3 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
2136 KB |
Output is correct |
7 |
Correct |
4 ms |
1884 KB |
Output is correct |
8 |
Correct |
3 ms |
1884 KB |
Output is correct |
9 |
Correct |
3 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
2136 KB |
Output is correct |
16 |
Correct |
12 ms |
2392 KB |
Output is correct |
17 |
Correct |
13 ms |
2396 KB |
Output is correct |
18 |
Correct |
3 ms |
2140 KB |
Output is correct |
19 |
Correct |
3 ms |
1884 KB |
Output is correct |
20 |
Correct |
11 ms |
2512 KB |
Output is correct |
21 |
Correct |
12 ms |
2260 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
1884 KB |
Output is correct |
24 |
Correct |
3 ms |
1884 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
452 KB |
Output is correct |
27 |
Correct |
6 ms |
2140 KB |
Output is correct |
28 |
Correct |
4 ms |
1884 KB |
Output is correct |
29 |
Correct |
3 ms |
1960 KB |
Output is correct |
30 |
Correct |
3 ms |
1884 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
19988 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
46 ms |
19492 KB |
Output is correct |
4 |
Correct |
47 ms |
18644 KB |
Output is correct |
5 |
Correct |
48 ms |
20084 KB |
Output is correct |
6 |
Correct |
47 ms |
22088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
17500 KB |
Output is correct |
2 |
Correct |
47 ms |
16104 KB |
Output is correct |
3 |
Correct |
54 ms |
15824 KB |
Output is correct |
4 |
Correct |
51 ms |
15828 KB |
Output is correct |
5 |
Correct |
51 ms |
15828 KB |
Output is correct |
6 |
Correct |
46 ms |
17612 KB |
Output is correct |
7 |
Correct |
45 ms |
17608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
17500 KB |
Output is correct |
2 |
Correct |
47 ms |
16104 KB |
Output is correct |
3 |
Correct |
54 ms |
15824 KB |
Output is correct |
4 |
Correct |
51 ms |
15828 KB |
Output is correct |
5 |
Correct |
51 ms |
15828 KB |
Output is correct |
6 |
Correct |
46 ms |
17612 KB |
Output is correct |
7 |
Correct |
45 ms |
17608 KB |
Output is correct |
8 |
Correct |
50 ms |
17560 KB |
Output is correct |
9 |
Correct |
45 ms |
19396 KB |
Output is correct |
10 |
Correct |
42 ms |
21968 KB |
Output is correct |
11 |
Correct |
43 ms |
21960 KB |
Output is correct |
12 |
Correct |
39 ms |
17352 KB |
Output is correct |
13 |
Correct |
41 ms |
17352 KB |
Output is correct |
14 |
Correct |
58 ms |
17644 KB |
Output is correct |
15 |
Correct |
51 ms |
17608 KB |
Output is correct |
16 |
Correct |
54 ms |
17608 KB |
Output is correct |
17 |
Correct |
52 ms |
17612 KB |
Output is correct |
18 |
Correct |
65 ms |
17636 KB |
Output is correct |
19 |
Correct |
48 ms |
17692 KB |
Output is correct |
20 |
Correct |
48 ms |
19656 KB |
Output is correct |
21 |
Correct |
47 ms |
20168 KB |
Output is correct |
22 |
Correct |
44 ms |
19656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
2136 KB |
Output is correct |
7 |
Correct |
4 ms |
1884 KB |
Output is correct |
8 |
Correct |
3 ms |
1884 KB |
Output is correct |
9 |
Correct |
3 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
2136 KB |
Output is correct |
16 |
Correct |
12 ms |
2392 KB |
Output is correct |
17 |
Correct |
13 ms |
2396 KB |
Output is correct |
18 |
Correct |
3 ms |
2140 KB |
Output is correct |
19 |
Correct |
3 ms |
1884 KB |
Output is correct |
20 |
Correct |
11 ms |
2512 KB |
Output is correct |
21 |
Correct |
12 ms |
2260 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
1884 KB |
Output is correct |
24 |
Correct |
3 ms |
1884 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
452 KB |
Output is correct |
27 |
Correct |
6 ms |
2140 KB |
Output is correct |
28 |
Correct |
4 ms |
1884 KB |
Output is correct |
29 |
Correct |
3 ms |
1960 KB |
Output is correct |
30 |
Correct |
3 ms |
1884 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
63 ms |
19988 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
46 ms |
19492 KB |
Output is correct |
39 |
Correct |
47 ms |
18644 KB |
Output is correct |
40 |
Correct |
48 ms |
20084 KB |
Output is correct |
41 |
Correct |
47 ms |
22088 KB |
Output is correct |
42 |
Correct |
47 ms |
17500 KB |
Output is correct |
43 |
Correct |
47 ms |
16104 KB |
Output is correct |
44 |
Correct |
54 ms |
15824 KB |
Output is correct |
45 |
Correct |
51 ms |
15828 KB |
Output is correct |
46 |
Correct |
51 ms |
15828 KB |
Output is correct |
47 |
Correct |
46 ms |
17612 KB |
Output is correct |
48 |
Correct |
45 ms |
17608 KB |
Output is correct |
49 |
Correct |
50 ms |
17560 KB |
Output is correct |
50 |
Correct |
45 ms |
19396 KB |
Output is correct |
51 |
Correct |
42 ms |
21968 KB |
Output is correct |
52 |
Correct |
43 ms |
21960 KB |
Output is correct |
53 |
Correct |
39 ms |
17352 KB |
Output is correct |
54 |
Correct |
41 ms |
17352 KB |
Output is correct |
55 |
Correct |
58 ms |
17644 KB |
Output is correct |
56 |
Correct |
51 ms |
17608 KB |
Output is correct |
57 |
Correct |
54 ms |
17608 KB |
Output is correct |
58 |
Correct |
52 ms |
17612 KB |
Output is correct |
59 |
Correct |
65 ms |
17636 KB |
Output is correct |
60 |
Correct |
48 ms |
17692 KB |
Output is correct |
61 |
Correct |
48 ms |
19656 KB |
Output is correct |
62 |
Correct |
47 ms |
20168 KB |
Output is correct |
63 |
Correct |
44 ms |
19656 KB |
Output is correct |
64 |
Correct |
47 ms |
19656 KB |
Output is correct |
65 |
Correct |
60 ms |
17732 KB |
Output is correct |
66 |
Correct |
60 ms |
17536 KB |
Output is correct |
67 |
Correct |
49 ms |
17672 KB |
Output is correct |
68 |
Correct |
34 ms |
17356 KB |
Output is correct |
69 |
Correct |
35 ms |
17388 KB |
Output is correct |
70 |
Correct |
51 ms |
20024 KB |
Output is correct |
71 |
Correct |
57 ms |
19148 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
4 ms |
1884 KB |
Output is correct |
74 |
Correct |
4 ms |
1884 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
4 ms |
2140 KB |
Output is correct |
78 |
Correct |
4 ms |
1880 KB |
Output is correct |
79 |
Correct |
3 ms |
1884 KB |
Output is correct |
80 |
Correct |
3 ms |
1884 KB |
Output is correct |
81 |
Correct |
0 ms |
348 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
0 ms |
404 KB |
Output is correct |
86 |
Correct |
11 ms |
2152 KB |
Output is correct |
87 |
Correct |
13 ms |
2396 KB |
Output is correct |
88 |
Correct |
12 ms |
2396 KB |
Output is correct |
89 |
Correct |
5 ms |
2128 KB |
Output is correct |
90 |
Correct |
3 ms |
1884 KB |
Output is correct |
91 |
Correct |
10 ms |
2556 KB |
Output is correct |
92 |
Correct |
20 ms |
2256 KB |
Output is correct |
93 |
Correct |
0 ms |
348 KB |
Output is correct |
94 |
Correct |
49 ms |
21768 KB |
Output is correct |
95 |
Correct |
50 ms |
21192 KB |
Output is correct |
96 |
Correct |
51 ms |
20512 KB |
Output is correct |
97 |
Correct |
48 ms |
21792 KB |
Output is correct |
98 |
Correct |
47 ms |
22228 KB |
Output is correct |
99 |
Correct |
55 ms |
17596 KB |
Output is correct |
100 |
Correct |
53 ms |
17536 KB |
Output is correct |
101 |
Correct |
53 ms |
17612 KB |
Output is correct |
102 |
Correct |
49 ms |
17868 KB |
Output is correct |
103 |
Correct |
52 ms |
19292 KB |
Output is correct |
104 |
Correct |
50 ms |
19916 KB |
Output is correct |
105 |
Correct |
44 ms |
19652 KB |
Output is correct |
106 |
Correct |
46 ms |
19660 KB |
Output is correct |
107 |
Correct |
49 ms |
19304 KB |
Output is correct |
108 |
Correct |
43 ms |
21960 KB |
Output is correct |
109 |
Correct |
41 ms |
21964 KB |
Output is correct |
110 |
Correct |
40 ms |
17452 KB |
Output is correct |
111 |
Correct |
50 ms |
17540 KB |
Output is correct |
112 |
Correct |
49 ms |
17608 KB |
Output is correct |
113 |
Correct |
49 ms |
17608 KB |
Output is correct |