#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int poziomy[19][100100];
struct wi{
vector<int> Q;
int wiel=0;
int poz=0;
int wchodze=0;
int wynik=0;
int ktora=0;
int suma=0;
}*w;
int jestem=1;
void ustaw_poziomy(int x)
{
for(int i=1;i<19;i++)
poziomy[i][x]=poziomy[i-1][poziomy[i-1][x]];
}
void dfs(int x,int ojciec)
{
w[x].wchodze=jestem;
jestem++;
for(int i=0;i<w[x].Q.size();i+=2)
{
int pomoc=w[x].Q[i];
if(pomoc==ojciec)
{
w[x].ktora=i;
continue;
}
w[pomoc].poz=w[x].poz+1;
poziomy[0][pomoc]=x;
ustaw_poziomy(pomoc);
dfs(pomoc,x);
}
}
int nasze_lca(int x,int y)
{
if(w[x].poz>w[y].poz)
swap(x,y);
for(int k=18;k>=0;k--)
if(w[y].poz-(1<<k)>=w[x].poz)
y=poziomy[k][y];
for(int k=18;k>=0;k--)
if(poziomy[k][x]!=poziomy[k][y])
{
x=poziomy[k][x];
y=poziomy[k][y];
}
if(x==y)
return x;
return poziomy[0][x];
}
int dfs2(int x,int ojc)
{
int suma=0;
for(int i=0;i<w[x].Q.size();i+=2)
{
int pom=w[x].Q[i];
if(pom==ojc)
continue;
suma+=dfs2(pom,x);
}
suma+=w[x].suma;
w[x].wynik=suma;
return suma;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,m,k,x,y;
cin>>n>>m>>k;
w=new wi[n+3];
for(int i=1;i<n;i++)
{
cin>>x>>y;
w[x].Q.push_back(y);
w[y].Q.push_back(x);
w[x].Q.push_back(i);
w[y].Q.push_back(i);
}
dfs(1,0);
for(int i=1;i<=m;i++)
{
int mam;
cin>>mam;
vector<pair<int,int> > tak;
for(int j=0;j<mam;j++)
{
cin>>x;
tak.push_back({w[x].wchodze,x});
}
sort(tak.begin(),tak.end());
for(int j=0;j<tak.size();j++)
{
x=tak[j].second;
y=tak[(j+1)%tak.size()].second;
int gdzie=nasze_lca(x,y);
w[x].suma++;
w[y].suma++;
w[gdzie].suma-=2;
}
}
int cos=dfs2(1,0);
vector<int> wypisz;;
for(int i=2;i<=n;i++)
{
if(w[i].wynik>=2*k)
{
wypisz.push_back(w[i].Q[w[i].ktora+1]);
}
}
sort(wypisz.begin(),wypisz.end());
cout<<wypisz.size()<<"\n";
for(int i=0;i<wypisz.size();i++)
cout<<wypisz[i]<<" ";
return 0;
}
Compilation message
railway.cpp: In function 'void dfs(int, int)':
railway.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<w[x].Q.size();i+=2)
| ~^~~~~~~~~~~~~~
railway.cpp: In function 'int dfs2(int, int)':
railway.cpp:60:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0;i<w[x].Q.size();i+=2)
| ~^~~~~~~~~~~~~~
railway.cpp: In function 'int main()':
railway.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int j=0;j<tak.size();j++)
| ~^~~~~~~~~~~
railway.cpp:120:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | for(int i=0;i<wypisz.size();i++)
| ~^~~~~~~~~~~~~~
railway.cpp:109:9: warning: unused variable 'cos' [-Wunused-variable]
109 | int cos=dfs2(1,0);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
2012 KB |
Output is correct |
3 |
Correct |
5 ms |
2012 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
2344 KB |
Output is correct |
7 |
Correct |
5 ms |
2132 KB |
Output is correct |
8 |
Correct |
4 ms |
2132 KB |
Output is correct |
9 |
Correct |
4 ms |
2132 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
2012 KB |
Output is correct |
3 |
Correct |
5 ms |
2012 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
2344 KB |
Output is correct |
7 |
Correct |
5 ms |
2132 KB |
Output is correct |
8 |
Correct |
4 ms |
2132 KB |
Output is correct |
9 |
Correct |
4 ms |
2132 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
32 ms |
2388 KB |
Output is correct |
16 |
Correct |
32 ms |
2396 KB |
Output is correct |
17 |
Correct |
34 ms |
2516 KB |
Output is correct |
18 |
Correct |
6 ms |
2388 KB |
Output is correct |
19 |
Correct |
7 ms |
2132 KB |
Output is correct |
20 |
Correct |
35 ms |
2592 KB |
Output is correct |
21 |
Correct |
36 ms |
2524 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
2004 KB |
Output is correct |
24 |
Correct |
5 ms |
2124 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
2392 KB |
Output is correct |
28 |
Correct |
8 ms |
2116 KB |
Output is correct |
29 |
Correct |
4 ms |
2132 KB |
Output is correct |
30 |
Correct |
4 ms |
2132 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
21152 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
146 ms |
20796 KB |
Output is correct |
4 |
Correct |
127 ms |
20284 KB |
Output is correct |
5 |
Correct |
220 ms |
21188 KB |
Output is correct |
6 |
Correct |
130 ms |
21304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
18368 KB |
Output is correct |
2 |
Correct |
102 ms |
16376 KB |
Output is correct |
3 |
Correct |
116 ms |
16276 KB |
Output is correct |
4 |
Correct |
98 ms |
16116 KB |
Output is correct |
5 |
Correct |
104 ms |
16076 KB |
Output is correct |
6 |
Correct |
91 ms |
18544 KB |
Output is correct |
7 |
Correct |
90 ms |
18412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
18368 KB |
Output is correct |
2 |
Correct |
102 ms |
16376 KB |
Output is correct |
3 |
Correct |
116 ms |
16276 KB |
Output is correct |
4 |
Correct |
98 ms |
16116 KB |
Output is correct |
5 |
Correct |
104 ms |
16076 KB |
Output is correct |
6 |
Correct |
91 ms |
18544 KB |
Output is correct |
7 |
Correct |
90 ms |
18412 KB |
Output is correct |
8 |
Correct |
128 ms |
18668 KB |
Output is correct |
9 |
Correct |
118 ms |
18552 KB |
Output is correct |
10 |
Correct |
129 ms |
21292 KB |
Output is correct |
11 |
Correct |
145 ms |
21288 KB |
Output is correct |
12 |
Correct |
149 ms |
16404 KB |
Output is correct |
13 |
Correct |
143 ms |
17764 KB |
Output is correct |
14 |
Correct |
121 ms |
17876 KB |
Output is correct |
15 |
Correct |
131 ms |
17928 KB |
Output is correct |
16 |
Correct |
115 ms |
18012 KB |
Output is correct |
17 |
Correct |
105 ms |
17988 KB |
Output is correct |
18 |
Correct |
110 ms |
17992 KB |
Output is correct |
19 |
Correct |
100 ms |
18124 KB |
Output is correct |
20 |
Correct |
79 ms |
20556 KB |
Output is correct |
21 |
Correct |
89 ms |
20696 KB |
Output is correct |
22 |
Correct |
91 ms |
20552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
2012 KB |
Output is correct |
3 |
Correct |
5 ms |
2012 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
2344 KB |
Output is correct |
7 |
Correct |
5 ms |
2132 KB |
Output is correct |
8 |
Correct |
4 ms |
2132 KB |
Output is correct |
9 |
Correct |
4 ms |
2132 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
32 ms |
2388 KB |
Output is correct |
16 |
Correct |
32 ms |
2396 KB |
Output is correct |
17 |
Correct |
34 ms |
2516 KB |
Output is correct |
18 |
Correct |
6 ms |
2388 KB |
Output is correct |
19 |
Correct |
7 ms |
2132 KB |
Output is correct |
20 |
Correct |
35 ms |
2592 KB |
Output is correct |
21 |
Correct |
36 ms |
2524 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
2004 KB |
Output is correct |
24 |
Correct |
5 ms |
2124 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
2392 KB |
Output is correct |
28 |
Correct |
8 ms |
2116 KB |
Output is correct |
29 |
Correct |
4 ms |
2132 KB |
Output is correct |
30 |
Correct |
4 ms |
2132 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
134 ms |
21152 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
146 ms |
20796 KB |
Output is correct |
39 |
Correct |
127 ms |
20284 KB |
Output is correct |
40 |
Correct |
220 ms |
21188 KB |
Output is correct |
41 |
Correct |
130 ms |
21304 KB |
Output is correct |
42 |
Correct |
86 ms |
18368 KB |
Output is correct |
43 |
Correct |
102 ms |
16376 KB |
Output is correct |
44 |
Correct |
116 ms |
16276 KB |
Output is correct |
45 |
Correct |
98 ms |
16116 KB |
Output is correct |
46 |
Correct |
104 ms |
16076 KB |
Output is correct |
47 |
Correct |
91 ms |
18544 KB |
Output is correct |
48 |
Correct |
90 ms |
18412 KB |
Output is correct |
49 |
Correct |
128 ms |
18668 KB |
Output is correct |
50 |
Correct |
118 ms |
18552 KB |
Output is correct |
51 |
Correct |
129 ms |
21292 KB |
Output is correct |
52 |
Correct |
145 ms |
21288 KB |
Output is correct |
53 |
Correct |
149 ms |
16404 KB |
Output is correct |
54 |
Correct |
143 ms |
17764 KB |
Output is correct |
55 |
Correct |
121 ms |
17876 KB |
Output is correct |
56 |
Correct |
131 ms |
17928 KB |
Output is correct |
57 |
Correct |
115 ms |
18012 KB |
Output is correct |
58 |
Correct |
105 ms |
17988 KB |
Output is correct |
59 |
Correct |
110 ms |
17992 KB |
Output is correct |
60 |
Correct |
100 ms |
18124 KB |
Output is correct |
61 |
Correct |
79 ms |
20556 KB |
Output is correct |
62 |
Correct |
89 ms |
20696 KB |
Output is correct |
63 |
Correct |
91 ms |
20552 KB |
Output is correct |
64 |
Correct |
94 ms |
20436 KB |
Output is correct |
65 |
Correct |
128 ms |
17992 KB |
Output is correct |
66 |
Correct |
191 ms |
17928 KB |
Output is correct |
67 |
Correct |
142 ms |
17928 KB |
Output is correct |
68 |
Correct |
91 ms |
17616 KB |
Output is correct |
69 |
Correct |
101 ms |
17616 KB |
Output is correct |
70 |
Correct |
122 ms |
20940 KB |
Output is correct |
71 |
Correct |
131 ms |
20196 KB |
Output is correct |
72 |
Correct |
0 ms |
340 KB |
Output is correct |
73 |
Correct |
5 ms |
2004 KB |
Output is correct |
74 |
Correct |
5 ms |
2120 KB |
Output is correct |
75 |
Correct |
0 ms |
336 KB |
Output is correct |
76 |
Correct |
1 ms |
340 KB |
Output is correct |
77 |
Correct |
5 ms |
2312 KB |
Output is correct |
78 |
Correct |
5 ms |
2132 KB |
Output is correct |
79 |
Correct |
4 ms |
2044 KB |
Output is correct |
80 |
Correct |
5 ms |
2132 KB |
Output is correct |
81 |
Correct |
1 ms |
340 KB |
Output is correct |
82 |
Correct |
0 ms |
340 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
0 ms |
340 KB |
Output is correct |
85 |
Correct |
0 ms |
340 KB |
Output is correct |
86 |
Correct |
29 ms |
2388 KB |
Output is correct |
87 |
Correct |
31 ms |
2480 KB |
Output is correct |
88 |
Correct |
30 ms |
2504 KB |
Output is correct |
89 |
Correct |
6 ms |
2396 KB |
Output is correct |
90 |
Correct |
5 ms |
2172 KB |
Output is correct |
91 |
Correct |
32 ms |
2532 KB |
Output is correct |
92 |
Correct |
39 ms |
2540 KB |
Output is correct |
93 |
Correct |
0 ms |
340 KB |
Output is correct |
94 |
Correct |
152 ms |
22944 KB |
Output is correct |
95 |
Correct |
144 ms |
22568 KB |
Output is correct |
96 |
Correct |
145 ms |
22092 KB |
Output is correct |
97 |
Correct |
177 ms |
22896 KB |
Output is correct |
98 |
Correct |
128 ms |
23364 KB |
Output is correct |
99 |
Correct |
121 ms |
17944 KB |
Output is correct |
100 |
Correct |
125 ms |
17992 KB |
Output is correct |
101 |
Correct |
104 ms |
17980 KB |
Output is correct |
102 |
Correct |
91 ms |
18124 KB |
Output is correct |
103 |
Correct |
82 ms |
20396 KB |
Output is correct |
104 |
Correct |
93 ms |
20572 KB |
Output is correct |
105 |
Correct |
77 ms |
20180 KB |
Output is correct |
106 |
Correct |
129 ms |
20440 KB |
Output is correct |
107 |
Correct |
123 ms |
20348 KB |
Output is correct |
108 |
Correct |
156 ms |
23008 KB |
Output is correct |
109 |
Correct |
131 ms |
22956 KB |
Output is correct |
110 |
Correct |
139 ms |
17676 KB |
Output is correct |
111 |
Correct |
145 ms |
17768 KB |
Output is correct |
112 |
Correct |
140 ms |
17888 KB |
Output is correct |
113 |
Correct |
107 ms |
17876 KB |
Output is correct |