#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 100001;
const ll VMAX = 1001;
const ll INF = (1LL << 60);
const ll MOD = 998244353;
const ll BLOCK = 447;
const ll base = 31;
const ll nr_of_bits = 21;
vector <int> sol;
vector <pii> v[NMAX];
int dp[NMAX][nr_of_bits + 1];
int sum[NMAX];
pii timp[NMAX];
int stamp;
bool isParent(int a, int b){
return (timp[a].first <= timp[b].first && timp[b].second <= timp[a].second);
}
int LCA(int a, int b){
int r = a, pas = nr_of_bits;
while(pas >= 0){
int nxt = dp[r][pas];
if(nxt != 0 && !isParent(nxt, b))
r = nxt;
pas--;
}
if(!isParent(r, b))
r = dp[r][0];
return r;
}
void DFS(int node, int p){
dp[node][0] = p;
timp[node].first = ++stamp;
for(auto x : v[node]){
if(x.first == p) continue;
DFS(x.first, node);
}
timp[node].second = stamp;
}
int c[NMAX];
bool cmp(int a, int b){
return timp[a].first < timp[b].first;
}
int k;
void Solve(int node, int p){
for(auto x : v[node]){
if(x.first == p) continue;
Solve(x.first, node);
sum[node] += sum[x.first];
if(sum[x.first] >= k){
sol.push_back(x.second);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, i;
cin >> n >> m >> k;
for(i = 1; i < n; i++){
int a, b;
cin >> a >> b;
v[a].push_back({b, i});
v[b].push_back({a, i});
}
DFS(1, 0);
for(int j = 1; j <= nr_of_bits; j++){
for(i = 1; i <= n; i++){
dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
}
for(i = 1; i <= m; i++){
int t;
cin >> t;
for(int j = 1; j <= t; j++) cin >> c[j];
vector <int> total, stiva;
sort(c + 1, c + t + 1, cmp);
total.push_back(c[t]);
for(int j = 1; j < t; j++){
total.push_back(c[j]);
total.push_back(LCA(c[j], c[j + 1]));
}
sort(total.begin(), total.end(), cmp);
for(int j = 0; j < total.size(); j++){
if(j > 0 && timp[total[j - 1]].first == timp[total[j]].first)
continue;
while(stiva.size() && timp[stiva.back()].second < timp[total[j]].first)
stiva.pop_back();
if(stiva.size()){
sum[stiva.back()]--;
sum[total[j]]++;
}
stiva.push_back(total[j]);
}
}
Solve(1, 0);
sort(sol.begin(), sol.end());
cout << sol.size() << "\n";
for(auto x : sol) cout << x << " ";
return 0;
}
Compilation message
railway.cpp: In function 'int main()':
railway.cpp:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int j = 0; j < total.size(); j++){
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2644 KB |
Output is correct |
2 |
Correct |
9 ms |
3924 KB |
Output is correct |
3 |
Correct |
6 ms |
3924 KB |
Output is correct |
4 |
Correct |
2 ms |
2680 KB |
Output is correct |
5 |
Correct |
2 ms |
2680 KB |
Output is correct |
6 |
Correct |
7 ms |
4564 KB |
Output is correct |
7 |
Correct |
7 ms |
4232 KB |
Output is correct |
8 |
Correct |
6 ms |
4096 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
2680 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2644 KB |
Output is correct |
2 |
Correct |
9 ms |
3924 KB |
Output is correct |
3 |
Correct |
6 ms |
3924 KB |
Output is correct |
4 |
Correct |
2 ms |
2680 KB |
Output is correct |
5 |
Correct |
2 ms |
2680 KB |
Output is correct |
6 |
Correct |
7 ms |
4564 KB |
Output is correct |
7 |
Correct |
7 ms |
4232 KB |
Output is correct |
8 |
Correct |
6 ms |
4096 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
2680 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
30 ms |
4416 KB |
Output is correct |
16 |
Correct |
32 ms |
4536 KB |
Output is correct |
17 |
Correct |
32 ms |
4556 KB |
Output is correct |
18 |
Correct |
10 ms |
4564 KB |
Output is correct |
19 |
Correct |
9 ms |
4232 KB |
Output is correct |
20 |
Correct |
28 ms |
4612 KB |
Output is correct |
21 |
Correct |
30 ms |
4556 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
6 ms |
4148 KB |
Output is correct |
24 |
Correct |
6 ms |
4108 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
7 ms |
4564 KB |
Output is correct |
28 |
Correct |
7 ms |
4232 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
7 ms |
4108 KB |
Output is correct |
31 |
Correct |
2 ms |
2680 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
24252 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
83 ms |
23968 KB |
Output is correct |
4 |
Correct |
98 ms |
23364 KB |
Output is correct |
5 |
Correct |
134 ms |
24292 KB |
Output is correct |
6 |
Correct |
112 ms |
24388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
19928 KB |
Output is correct |
2 |
Correct |
79 ms |
16516 KB |
Output is correct |
3 |
Correct |
101 ms |
16140 KB |
Output is correct |
4 |
Correct |
101 ms |
16188 KB |
Output is correct |
5 |
Correct |
86 ms |
16304 KB |
Output is correct |
6 |
Correct |
80 ms |
20048 KB |
Output is correct |
7 |
Correct |
77 ms |
20028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
19928 KB |
Output is correct |
2 |
Correct |
79 ms |
16516 KB |
Output is correct |
3 |
Correct |
101 ms |
16140 KB |
Output is correct |
4 |
Correct |
101 ms |
16188 KB |
Output is correct |
5 |
Correct |
86 ms |
16304 KB |
Output is correct |
6 |
Correct |
80 ms |
20048 KB |
Output is correct |
7 |
Correct |
77 ms |
20028 KB |
Output is correct |
8 |
Correct |
94 ms |
20200 KB |
Output is correct |
9 |
Correct |
100 ms |
21952 KB |
Output is correct |
10 |
Correct |
110 ms |
26160 KB |
Output is correct |
11 |
Correct |
125 ms |
26136 KB |
Output is correct |
12 |
Correct |
70 ms |
17688 KB |
Output is correct |
13 |
Correct |
76 ms |
17664 KB |
Output is correct |
14 |
Correct |
97 ms |
17888 KB |
Output is correct |
15 |
Correct |
117 ms |
17856 KB |
Output is correct |
16 |
Correct |
95 ms |
17924 KB |
Output is correct |
17 |
Correct |
80 ms |
17936 KB |
Output is correct |
18 |
Correct |
85 ms |
18080 KB |
Output is correct |
19 |
Correct |
81 ms |
18308 KB |
Output is correct |
20 |
Correct |
84 ms |
22128 KB |
Output is correct |
21 |
Correct |
108 ms |
22216 KB |
Output is correct |
22 |
Correct |
95 ms |
22064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2644 KB |
Output is correct |
2 |
Correct |
9 ms |
3924 KB |
Output is correct |
3 |
Correct |
6 ms |
3924 KB |
Output is correct |
4 |
Correct |
2 ms |
2680 KB |
Output is correct |
5 |
Correct |
2 ms |
2680 KB |
Output is correct |
6 |
Correct |
7 ms |
4564 KB |
Output is correct |
7 |
Correct |
7 ms |
4232 KB |
Output is correct |
8 |
Correct |
6 ms |
4096 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
2680 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
30 ms |
4416 KB |
Output is correct |
16 |
Correct |
32 ms |
4536 KB |
Output is correct |
17 |
Correct |
32 ms |
4556 KB |
Output is correct |
18 |
Correct |
10 ms |
4564 KB |
Output is correct |
19 |
Correct |
9 ms |
4232 KB |
Output is correct |
20 |
Correct |
28 ms |
4612 KB |
Output is correct |
21 |
Correct |
30 ms |
4556 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
6 ms |
4148 KB |
Output is correct |
24 |
Correct |
6 ms |
4108 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
7 ms |
4564 KB |
Output is correct |
28 |
Correct |
7 ms |
4232 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
7 ms |
4108 KB |
Output is correct |
31 |
Correct |
2 ms |
2680 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
91 ms |
24252 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
83 ms |
23968 KB |
Output is correct |
39 |
Correct |
98 ms |
23364 KB |
Output is correct |
40 |
Correct |
134 ms |
24292 KB |
Output is correct |
41 |
Correct |
112 ms |
24388 KB |
Output is correct |
42 |
Correct |
80 ms |
19928 KB |
Output is correct |
43 |
Correct |
79 ms |
16516 KB |
Output is correct |
44 |
Correct |
101 ms |
16140 KB |
Output is correct |
45 |
Correct |
101 ms |
16188 KB |
Output is correct |
46 |
Correct |
86 ms |
16304 KB |
Output is correct |
47 |
Correct |
80 ms |
20048 KB |
Output is correct |
48 |
Correct |
77 ms |
20028 KB |
Output is correct |
49 |
Correct |
94 ms |
20200 KB |
Output is correct |
50 |
Correct |
100 ms |
21952 KB |
Output is correct |
51 |
Correct |
110 ms |
26160 KB |
Output is correct |
52 |
Correct |
125 ms |
26136 KB |
Output is correct |
53 |
Correct |
70 ms |
17688 KB |
Output is correct |
54 |
Correct |
76 ms |
17664 KB |
Output is correct |
55 |
Correct |
97 ms |
17888 KB |
Output is correct |
56 |
Correct |
117 ms |
17856 KB |
Output is correct |
57 |
Correct |
95 ms |
17924 KB |
Output is correct |
58 |
Correct |
80 ms |
17936 KB |
Output is correct |
59 |
Correct |
85 ms |
18080 KB |
Output is correct |
60 |
Correct |
81 ms |
18308 KB |
Output is correct |
61 |
Correct |
84 ms |
22128 KB |
Output is correct |
62 |
Correct |
108 ms |
22216 KB |
Output is correct |
63 |
Correct |
95 ms |
22064 KB |
Output is correct |
64 |
Correct |
85 ms |
22016 KB |
Output is correct |
65 |
Correct |
92 ms |
17900 KB |
Output is correct |
66 |
Correct |
131 ms |
17820 KB |
Output is correct |
67 |
Correct |
102 ms |
17772 KB |
Output is correct |
68 |
Correct |
68 ms |
17656 KB |
Output is correct |
69 |
Correct |
64 ms |
17588 KB |
Output is correct |
70 |
Correct |
83 ms |
22336 KB |
Output is correct |
71 |
Correct |
110 ms |
21724 KB |
Output is correct |
72 |
Correct |
2 ms |
2644 KB |
Output is correct |
73 |
Correct |
8 ms |
4108 KB |
Output is correct |
74 |
Correct |
8 ms |
4180 KB |
Output is correct |
75 |
Correct |
2 ms |
2644 KB |
Output is correct |
76 |
Correct |
2 ms |
2680 KB |
Output is correct |
77 |
Correct |
7 ms |
4564 KB |
Output is correct |
78 |
Correct |
7 ms |
4244 KB |
Output is correct |
79 |
Correct |
6 ms |
4052 KB |
Output is correct |
80 |
Correct |
5 ms |
4100 KB |
Output is correct |
81 |
Correct |
2 ms |
2644 KB |
Output is correct |
82 |
Correct |
2 ms |
2644 KB |
Output is correct |
83 |
Correct |
2 ms |
2644 KB |
Output is correct |
84 |
Correct |
2 ms |
2644 KB |
Output is correct |
85 |
Correct |
2 ms |
2644 KB |
Output is correct |
86 |
Correct |
28 ms |
4504 KB |
Output is correct |
87 |
Correct |
28 ms |
4480 KB |
Output is correct |
88 |
Correct |
30 ms |
4484 KB |
Output is correct |
89 |
Correct |
7 ms |
4564 KB |
Output is correct |
90 |
Correct |
6 ms |
4180 KB |
Output is correct |
91 |
Correct |
32 ms |
4576 KB |
Output is correct |
92 |
Correct |
29 ms |
4692 KB |
Output is correct |
93 |
Correct |
2 ms |
2644 KB |
Output is correct |
94 |
Correct |
105 ms |
26096 KB |
Output is correct |
95 |
Correct |
140 ms |
25744 KB |
Output is correct |
96 |
Correct |
80 ms |
25216 KB |
Output is correct |
97 |
Correct |
97 ms |
25992 KB |
Output is correct |
98 |
Correct |
110 ms |
26416 KB |
Output is correct |
99 |
Correct |
119 ms |
17940 KB |
Output is correct |
100 |
Correct |
114 ms |
17868 KB |
Output is correct |
101 |
Correct |
89 ms |
17960 KB |
Output is correct |
102 |
Correct |
86 ms |
18252 KB |
Output is correct |
103 |
Correct |
91 ms |
21836 KB |
Output is correct |
104 |
Correct |
100 ms |
22124 KB |
Output is correct |
105 |
Correct |
86 ms |
21804 KB |
Output is correct |
106 |
Correct |
96 ms |
22164 KB |
Output is correct |
107 |
Correct |
104 ms |
21848 KB |
Output is correct |
108 |
Correct |
111 ms |
26112 KB |
Output is correct |
109 |
Correct |
103 ms |
26116 KB |
Output is correct |
110 |
Correct |
75 ms |
17656 KB |
Output is correct |
111 |
Correct |
77 ms |
17700 KB |
Output is correct |
112 |
Correct |
87 ms |
17824 KB |
Output is correct |
113 |
Correct |
105 ms |
17828 KB |
Output is correct |