#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
vector<int> adj[100005];
vector<int> person[50005];
int st[100005];
int timer = 1;
int h[100005];
int jmp[100005][20];
void dfs(int node, int par = -1) {
st[node] = timer++;
for (int j = 1; j < 20; j++) {
jmp[node][j] = jmp[jmp[node][j-1]][j-1];
}
for (auto nxt : adj[node]) {
if (nxt == par) continue;
h[nxt] = h[node] + 1;
jmp[nxt][0] = node;
dfs(nxt, node);
}
}
int lca(int a, int b) {
if (h[a] > h[b]) swap(a, b);
for (int j = 19; j >= 0; j--) {
if (h[jmp[b][j]] >= h[a]) b = jmp[b][j];
}
if (a == b) return a;
for (int j = 19; j >= 0; j--) {
if (jmp[a][j] != jmp[b][j]) {
a = jmp[a][j]; b = jmp[b][j];
}
}
return jmp[a][0];
}
int node[100005];
int val[100005];
int dfs2(int cur, int par) {
val[cur] = node[cur];
for (auto nxt : adj[cur]) {
if (nxt == par) continue;
val[cur] += dfs2(nxt, cur);
}
return val[cur];
}
vector<pair<int, int>> edges;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int n, m, k; cin >> n >> m >> k;
for (int i = 0; i < n - 1; i++) {
int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); edges.emplace_back(a, b);
}
h[1] = 1;
jmp[1][0] = 1;
dfs(1);
for (int i = 0; i < m; i++) {
int s ;cin >> s;
vector<int> temp;
for (int j = 0; j < s; j++) {
int t; cin >> t; temp.push_back(t);
}
sort(temp.begin(), temp.end(), [](int a, int b) {
return st[a] < st[b];
});
for (int j = 0; j < s; j++) {
int a = temp[j], b = temp[(j + 1) % s];
int l = lca(a, b);
node[a]++; node[b]++; node[l] -= 2;
}
}
vector<int> ans;
dfs2(1, -1);
int i = 1;
for (auto edge :edges) {
int a = (h[edge.first] > h[edge.second] ? edge.first : edge.second);
if (val[a] >= 2 * k) ans.push_back(i);
i++;
}
cout << ans.size() << endl;
for (auto a : ans) cout << a << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3796 KB |
Output is correct |
2 |
Correct |
8 ms |
5264 KB |
Output is correct |
3 |
Correct |
10 ms |
5332 KB |
Output is correct |
4 |
Correct |
3 ms |
3796 KB |
Output is correct |
5 |
Correct |
4 ms |
3852 KB |
Output is correct |
6 |
Correct |
8 ms |
5716 KB |
Output is correct |
7 |
Correct |
8 ms |
5396 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
3 ms |
3852 KB |
Output is correct |
11 |
Correct |
3 ms |
3796 KB |
Output is correct |
12 |
Correct |
3 ms |
3796 KB |
Output is correct |
13 |
Correct |
3 ms |
3924 KB |
Output is correct |
14 |
Correct |
3 ms |
3796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3796 KB |
Output is correct |
2 |
Correct |
8 ms |
5264 KB |
Output is correct |
3 |
Correct |
10 ms |
5332 KB |
Output is correct |
4 |
Correct |
3 ms |
3796 KB |
Output is correct |
5 |
Correct |
4 ms |
3852 KB |
Output is correct |
6 |
Correct |
8 ms |
5716 KB |
Output is correct |
7 |
Correct |
8 ms |
5396 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
3 ms |
3852 KB |
Output is correct |
11 |
Correct |
3 ms |
3796 KB |
Output is correct |
12 |
Correct |
3 ms |
3796 KB |
Output is correct |
13 |
Correct |
3 ms |
3924 KB |
Output is correct |
14 |
Correct |
3 ms |
3796 KB |
Output is correct |
15 |
Correct |
33 ms |
5580 KB |
Output is correct |
16 |
Correct |
30 ms |
5684 KB |
Output is correct |
17 |
Correct |
32 ms |
5764 KB |
Output is correct |
18 |
Correct |
9 ms |
5716 KB |
Output is correct |
19 |
Correct |
8 ms |
5404 KB |
Output is correct |
20 |
Correct |
34 ms |
5872 KB |
Output is correct |
21 |
Correct |
36 ms |
5716 KB |
Output is correct |
22 |
Correct |
3 ms |
3796 KB |
Output is correct |
23 |
Correct |
10 ms |
5272 KB |
Output is correct |
24 |
Correct |
9 ms |
5332 KB |
Output is correct |
25 |
Correct |
3 ms |
3796 KB |
Output is correct |
26 |
Correct |
3 ms |
3796 KB |
Output is correct |
27 |
Correct |
9 ms |
5780 KB |
Output is correct |
28 |
Correct |
9 ms |
5400 KB |
Output is correct |
29 |
Correct |
7 ms |
5268 KB |
Output is correct |
30 |
Correct |
9 ms |
5272 KB |
Output is correct |
31 |
Correct |
3 ms |
3796 KB |
Output is correct |
32 |
Correct |
3 ms |
3796 KB |
Output is correct |
33 |
Correct |
3 ms |
3796 KB |
Output is correct |
34 |
Correct |
2 ms |
3796 KB |
Output is correct |
35 |
Correct |
2 ms |
3852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
28100 KB |
Output is correct |
2 |
Correct |
2 ms |
3796 KB |
Output is correct |
3 |
Correct |
125 ms |
27416 KB |
Output is correct |
4 |
Correct |
111 ms |
26708 KB |
Output is correct |
5 |
Correct |
137 ms |
27968 KB |
Output is correct |
6 |
Correct |
100 ms |
28352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
22720 KB |
Output is correct |
2 |
Correct |
115 ms |
19392 KB |
Output is correct |
3 |
Correct |
114 ms |
18944 KB |
Output is correct |
4 |
Correct |
135 ms |
19028 KB |
Output is correct |
5 |
Correct |
125 ms |
19028 KB |
Output is correct |
6 |
Correct |
110 ms |
22912 KB |
Output is correct |
7 |
Correct |
104 ms |
22672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
22720 KB |
Output is correct |
2 |
Correct |
115 ms |
19392 KB |
Output is correct |
3 |
Correct |
114 ms |
18944 KB |
Output is correct |
4 |
Correct |
135 ms |
19028 KB |
Output is correct |
5 |
Correct |
125 ms |
19028 KB |
Output is correct |
6 |
Correct |
110 ms |
22912 KB |
Output is correct |
7 |
Correct |
104 ms |
22672 KB |
Output is correct |
8 |
Correct |
108 ms |
22940 KB |
Output is correct |
9 |
Correct |
110 ms |
22988 KB |
Output is correct |
10 |
Correct |
117 ms |
28152 KB |
Output is correct |
11 |
Correct |
119 ms |
28032 KB |
Output is correct |
12 |
Correct |
99 ms |
18872 KB |
Output is correct |
13 |
Correct |
94 ms |
18880 KB |
Output is correct |
14 |
Correct |
112 ms |
18960 KB |
Output is correct |
15 |
Correct |
116 ms |
18976 KB |
Output is correct |
16 |
Correct |
126 ms |
19100 KB |
Output is correct |
17 |
Correct |
132 ms |
19032 KB |
Output is correct |
18 |
Correct |
109 ms |
19000 KB |
Output is correct |
19 |
Correct |
124 ms |
19352 KB |
Output is correct |
20 |
Correct |
107 ms |
23008 KB |
Output is correct |
21 |
Correct |
109 ms |
23260 KB |
Output is correct |
22 |
Correct |
92 ms |
23100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3796 KB |
Output is correct |
2 |
Correct |
8 ms |
5264 KB |
Output is correct |
3 |
Correct |
10 ms |
5332 KB |
Output is correct |
4 |
Correct |
3 ms |
3796 KB |
Output is correct |
5 |
Correct |
4 ms |
3852 KB |
Output is correct |
6 |
Correct |
8 ms |
5716 KB |
Output is correct |
7 |
Correct |
8 ms |
5396 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
3 ms |
3852 KB |
Output is correct |
11 |
Correct |
3 ms |
3796 KB |
Output is correct |
12 |
Correct |
3 ms |
3796 KB |
Output is correct |
13 |
Correct |
3 ms |
3924 KB |
Output is correct |
14 |
Correct |
3 ms |
3796 KB |
Output is correct |
15 |
Correct |
33 ms |
5580 KB |
Output is correct |
16 |
Correct |
30 ms |
5684 KB |
Output is correct |
17 |
Correct |
32 ms |
5764 KB |
Output is correct |
18 |
Correct |
9 ms |
5716 KB |
Output is correct |
19 |
Correct |
8 ms |
5404 KB |
Output is correct |
20 |
Correct |
34 ms |
5872 KB |
Output is correct |
21 |
Correct |
36 ms |
5716 KB |
Output is correct |
22 |
Correct |
3 ms |
3796 KB |
Output is correct |
23 |
Correct |
10 ms |
5272 KB |
Output is correct |
24 |
Correct |
9 ms |
5332 KB |
Output is correct |
25 |
Correct |
3 ms |
3796 KB |
Output is correct |
26 |
Correct |
3 ms |
3796 KB |
Output is correct |
27 |
Correct |
9 ms |
5780 KB |
Output is correct |
28 |
Correct |
9 ms |
5400 KB |
Output is correct |
29 |
Correct |
7 ms |
5268 KB |
Output is correct |
30 |
Correct |
9 ms |
5272 KB |
Output is correct |
31 |
Correct |
3 ms |
3796 KB |
Output is correct |
32 |
Correct |
3 ms |
3796 KB |
Output is correct |
33 |
Correct |
3 ms |
3796 KB |
Output is correct |
34 |
Correct |
2 ms |
3796 KB |
Output is correct |
35 |
Correct |
2 ms |
3852 KB |
Output is correct |
36 |
Correct |
138 ms |
28100 KB |
Output is correct |
37 |
Correct |
2 ms |
3796 KB |
Output is correct |
38 |
Correct |
125 ms |
27416 KB |
Output is correct |
39 |
Correct |
111 ms |
26708 KB |
Output is correct |
40 |
Correct |
137 ms |
27968 KB |
Output is correct |
41 |
Correct |
100 ms |
28352 KB |
Output is correct |
42 |
Correct |
103 ms |
22720 KB |
Output is correct |
43 |
Correct |
115 ms |
19392 KB |
Output is correct |
44 |
Correct |
114 ms |
18944 KB |
Output is correct |
45 |
Correct |
135 ms |
19028 KB |
Output is correct |
46 |
Correct |
125 ms |
19028 KB |
Output is correct |
47 |
Correct |
110 ms |
22912 KB |
Output is correct |
48 |
Correct |
104 ms |
22672 KB |
Output is correct |
49 |
Correct |
108 ms |
22940 KB |
Output is correct |
50 |
Correct |
110 ms |
22988 KB |
Output is correct |
51 |
Correct |
117 ms |
28152 KB |
Output is correct |
52 |
Correct |
119 ms |
28032 KB |
Output is correct |
53 |
Correct |
99 ms |
18872 KB |
Output is correct |
54 |
Correct |
94 ms |
18880 KB |
Output is correct |
55 |
Correct |
112 ms |
18960 KB |
Output is correct |
56 |
Correct |
116 ms |
18976 KB |
Output is correct |
57 |
Correct |
126 ms |
19100 KB |
Output is correct |
58 |
Correct |
132 ms |
19032 KB |
Output is correct |
59 |
Correct |
109 ms |
19000 KB |
Output is correct |
60 |
Correct |
124 ms |
19352 KB |
Output is correct |
61 |
Correct |
107 ms |
23008 KB |
Output is correct |
62 |
Correct |
109 ms |
23260 KB |
Output is correct |
63 |
Correct |
92 ms |
23100 KB |
Output is correct |
64 |
Correct |
104 ms |
23144 KB |
Output is correct |
65 |
Correct |
132 ms |
19032 KB |
Output is correct |
66 |
Correct |
132 ms |
18968 KB |
Output is correct |
67 |
Correct |
124 ms |
18876 KB |
Output is correct |
68 |
Correct |
81 ms |
18780 KB |
Output is correct |
69 |
Correct |
78 ms |
18840 KB |
Output is correct |
70 |
Correct |
110 ms |
23620 KB |
Output is correct |
71 |
Correct |
112 ms |
22856 KB |
Output is correct |
72 |
Correct |
2 ms |
3852 KB |
Output is correct |
73 |
Correct |
9 ms |
5276 KB |
Output is correct |
74 |
Correct |
8 ms |
5256 KB |
Output is correct |
75 |
Correct |
4 ms |
3852 KB |
Output is correct |
76 |
Correct |
3 ms |
3796 KB |
Output is correct |
77 |
Correct |
8 ms |
5716 KB |
Output is correct |
78 |
Correct |
8 ms |
5332 KB |
Output is correct |
79 |
Correct |
8 ms |
5332 KB |
Output is correct |
80 |
Correct |
7 ms |
5332 KB |
Output is correct |
81 |
Correct |
3 ms |
3796 KB |
Output is correct |
82 |
Correct |
3 ms |
3796 KB |
Output is correct |
83 |
Correct |
3 ms |
3796 KB |
Output is correct |
84 |
Correct |
3 ms |
3796 KB |
Output is correct |
85 |
Correct |
3 ms |
3796 KB |
Output is correct |
86 |
Correct |
30 ms |
5588 KB |
Output is correct |
87 |
Correct |
31 ms |
5692 KB |
Output is correct |
88 |
Correct |
31 ms |
5764 KB |
Output is correct |
89 |
Correct |
9 ms |
5696 KB |
Output is correct |
90 |
Correct |
7 ms |
5404 KB |
Output is correct |
91 |
Correct |
35 ms |
5792 KB |
Output is correct |
92 |
Correct |
36 ms |
5760 KB |
Output is correct |
93 |
Correct |
2 ms |
3796 KB |
Output is correct |
94 |
Correct |
114 ms |
28036 KB |
Output is correct |
95 |
Correct |
109 ms |
27492 KB |
Output is correct |
96 |
Correct |
111 ms |
26684 KB |
Output is correct |
97 |
Correct |
117 ms |
28024 KB |
Output is correct |
98 |
Correct |
105 ms |
28436 KB |
Output is correct |
99 |
Correct |
121 ms |
19008 KB |
Output is correct |
100 |
Correct |
116 ms |
18980 KB |
Output is correct |
101 |
Correct |
102 ms |
18956 KB |
Output is correct |
102 |
Correct |
114 ms |
19544 KB |
Output is correct |
103 |
Correct |
86 ms |
22800 KB |
Output is correct |
104 |
Correct |
98 ms |
23312 KB |
Output is correct |
105 |
Correct |
88 ms |
22676 KB |
Output is correct |
106 |
Correct |
104 ms |
23224 KB |
Output is correct |
107 |
Correct |
107 ms |
23076 KB |
Output is correct |
108 |
Correct |
101 ms |
28100 KB |
Output is correct |
109 |
Correct |
98 ms |
28160 KB |
Output is correct |
110 |
Correct |
87 ms |
18860 KB |
Output is correct |
111 |
Correct |
81 ms |
18884 KB |
Output is correct |
112 |
Correct |
114 ms |
18912 KB |
Output is correct |
113 |
Correct |
107 ms |
18932 KB |
Output is correct |