#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e5 + 1, MAXM = 5e4+10, MAXLOG = 21;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m, k;
vector < pair < int, int > > g[MAXN];
void read_graph()
{
cin >> n >> m >> k;
int from, to;
for (int i = 1; i < n; ++ i)
{
cin >> from >> to;
g[from].push_back({to, i});
g[to].push_back({from, i});
}
}
int p[MAXN], lvl[MAXN];
void dfs(int beg, int par, int depth)
{
p[beg] = par;
lvl[beg] = depth;
int nb;
for (int i = 0; i < g[beg].size(); ++ i)
{
nb = g[beg][i].first;
if(lvl[nb] == 0)dfs(nb, beg, depth+1);
}
}
int jump[MAXN][MAXLOG];
void fill_jump()
{
for (int i = 1; i <= n; ++ i)
jump[i][0] = p[i];
for (int j = 1; j < MAXLOG; ++ j)
for (int i = 1; i <= n; ++ i)
jump[i][j] = jump[jump[i][j-1]][j-1];
}
int move_up(int v, int dist)
{
for (int i = 0; (1 << i) <= dist; ++ i)
{
if((1 << i) & dist)
v = jump[v][i];
}
return v;
}
int lca(int u, int v)
{
if(lvl[u] > lvl[v])swap(u, v);
int diff = lvl[v] - lvl[u];
v = move_up(v, diff);
if(u == v)return u;
for (int i = MAXLOG - 1; i >= 0; -- i)
{
if(jump[u][i] != jump[v][i])
{
u = jump[u][i];
v = jump[v][i];
}
}
return p[u];
}
int s;
vector < int > que;
vector < int > endpoints[MAXN], startpoints[MAXN];
int used[MAXN];
int ans[MAXN];
bitset < MAXM > dfs2(int beg)
{
used[beg] = 1;
int nb, id;
bitset < MAXM > bs, vs;
for (int i = 0; i < g[beg].size(); ++ i)
{
nb = g[beg][i].first;
id = g[beg][i].second;
if(!used[nb])
{
vs = dfs2(nb);
bs = (bs | vs);
ans[id] += vs.count();
}
}
for (int i = 0; i < endpoints[beg].size(); ++ i)
bs[endpoints[beg][i]] = 1;
for (int i = 0; i < startpoints[beg].size(); ++ i)
bs[startpoints[beg][i]] = 0;
return bs;
}
void read_queries()
{
int xx;
for (int i = 1; i <= m; ++ i)
{
cin >> s >> xx;
int lcaa = xx;
que.clear();
que.push_back(xx);
for (int j = 2; j <= s; ++ j)
{
cin >> xx;
que.push_back(xx);
lcaa = lca(lcaa, xx);
}
startpoints[lcaa].push_back(i);
for (int j = 0; j < que.size(); ++ j)
{
endpoints[que[j]].push_back(i);
}
}
}
int main()
{
speed();
read_graph();
dfs(1, 0, 1);
fill_jump();
read_queries();
dfs2(1);
vector < int > anss;
for (int i = 1; i <= n; ++ i)
{
if(ans[i] >= k)anss.push_back(i);
}
cout << anss.size() << endl;
for (int i = 0; i < anss.size(); ++ i)
cout << anss[i] << " ";
cout << endl;
return 0;
}
Compilation message
railway.cpp: In function 'void dfs(int, int, int)':
railway.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < g[beg].size(); ++ i)
| ~~^~~~~~~~~~~~~~~
railway.cpp: In function 'std::bitset<50010> dfs2(int)':
railway.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i = 0; i < g[beg].size(); ++ i)
| ~~^~~~~~~~~~~~~~~
railway.cpp:93:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = 0; i < endpoints[beg].size(); ++ i)
| ~~^~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:95:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int i = 0; i < startpoints[beg].size(); ++ i)
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp: In function 'void read_queries()':
railway.cpp:115:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for (int j = 0; j < que.size(); ++ j)
| ~~^~~~~~~~~~~~
railway.cpp: In function 'int main()':
railway.cpp:140:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for (int i = 0; i < anss.size(); ++ i)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
28 ms |
11608 KB |
Output is correct |
3 |
Correct |
27 ms |
11608 KB |
Output is correct |
4 |
Correct |
2 ms |
11100 KB |
Output is correct |
5 |
Correct |
2 ms |
11100 KB |
Output is correct |
6 |
Correct |
61 ms |
73052 KB |
Output is correct |
7 |
Correct |
34 ms |
23892 KB |
Output is correct |
8 |
Correct |
26 ms |
11532 KB |
Output is correct |
9 |
Correct |
27 ms |
11612 KB |
Output is correct |
10 |
Correct |
3 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
3 ms |
10844 KB |
Output is correct |
13 |
Correct |
2 ms |
11100 KB |
Output is correct |
14 |
Correct |
3 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
28 ms |
11608 KB |
Output is correct |
3 |
Correct |
27 ms |
11608 KB |
Output is correct |
4 |
Correct |
2 ms |
11100 KB |
Output is correct |
5 |
Correct |
2 ms |
11100 KB |
Output is correct |
6 |
Correct |
61 ms |
73052 KB |
Output is correct |
7 |
Correct |
34 ms |
23892 KB |
Output is correct |
8 |
Correct |
26 ms |
11532 KB |
Output is correct |
9 |
Correct |
27 ms |
11612 KB |
Output is correct |
10 |
Correct |
3 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
3 ms |
10844 KB |
Output is correct |
13 |
Correct |
2 ms |
11100 KB |
Output is correct |
14 |
Correct |
3 ms |
11100 KB |
Output is correct |
15 |
Correct |
36 ms |
12124 KB |
Output is correct |
16 |
Correct |
36 ms |
12212 KB |
Output is correct |
17 |
Correct |
41 ms |
12244 KB |
Output is correct |
18 |
Correct |
61 ms |
73052 KB |
Output is correct |
19 |
Correct |
35 ms |
23808 KB |
Output is correct |
20 |
Correct |
40 ms |
12380 KB |
Output is correct |
21 |
Correct |
36 ms |
12120 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
29 ms |
11672 KB |
Output is correct |
24 |
Correct |
28 ms |
11608 KB |
Output is correct |
25 |
Correct |
3 ms |
11296 KB |
Output is correct |
26 |
Correct |
3 ms |
11096 KB |
Output is correct |
27 |
Correct |
67 ms |
73152 KB |
Output is correct |
28 |
Correct |
35 ms |
23644 KB |
Output is correct |
29 |
Correct |
26 ms |
11352 KB |
Output is correct |
30 |
Correct |
34 ms |
11352 KB |
Output is correct |
31 |
Correct |
2 ms |
11100 KB |
Output is correct |
32 |
Correct |
2 ms |
11100 KB |
Output is correct |
33 |
Correct |
3 ms |
11100 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
402 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
340 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
340 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
28 ms |
11608 KB |
Output is correct |
3 |
Correct |
27 ms |
11608 KB |
Output is correct |
4 |
Correct |
2 ms |
11100 KB |
Output is correct |
5 |
Correct |
2 ms |
11100 KB |
Output is correct |
6 |
Correct |
61 ms |
73052 KB |
Output is correct |
7 |
Correct |
34 ms |
23892 KB |
Output is correct |
8 |
Correct |
26 ms |
11532 KB |
Output is correct |
9 |
Correct |
27 ms |
11612 KB |
Output is correct |
10 |
Correct |
3 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
3 ms |
10844 KB |
Output is correct |
13 |
Correct |
2 ms |
11100 KB |
Output is correct |
14 |
Correct |
3 ms |
11100 KB |
Output is correct |
15 |
Correct |
36 ms |
12124 KB |
Output is correct |
16 |
Correct |
36 ms |
12212 KB |
Output is correct |
17 |
Correct |
41 ms |
12244 KB |
Output is correct |
18 |
Correct |
61 ms |
73052 KB |
Output is correct |
19 |
Correct |
35 ms |
23808 KB |
Output is correct |
20 |
Correct |
40 ms |
12380 KB |
Output is correct |
21 |
Correct |
36 ms |
12120 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
29 ms |
11672 KB |
Output is correct |
24 |
Correct |
28 ms |
11608 KB |
Output is correct |
25 |
Correct |
3 ms |
11296 KB |
Output is correct |
26 |
Correct |
3 ms |
11096 KB |
Output is correct |
27 |
Correct |
67 ms |
73152 KB |
Output is correct |
28 |
Correct |
35 ms |
23644 KB |
Output is correct |
29 |
Correct |
26 ms |
11352 KB |
Output is correct |
30 |
Correct |
34 ms |
11352 KB |
Output is correct |
31 |
Correct |
2 ms |
11100 KB |
Output is correct |
32 |
Correct |
2 ms |
11100 KB |
Output is correct |
33 |
Correct |
3 ms |
11100 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
36 |
Runtime error |
402 ms |
524288 KB |
Execution killed with signal 9 |
37 |
Halted |
0 ms |
0 KB |
- |