当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5927:Auxiliary Set

题目描述
Given a rooted tree with n vertices, some of the vertices are important.

An auxiliary set is a set containing vertices satisfying at least one of the two conditions:

$\bullet $It is an important vertex
$\bullet $It is the least common ancestor of two different important vertices.

You are given a tree with n vertices (1 is the root) and q queries.

Each query is a set of nodes which indicates the unimportant vertices in the tree. Answer the size (i.e. number of vertices) of the auxiliary set for each query.
输入解释
The first line contains only one integer T ($T \leq 1000$), which indicates the number of test cases.

For each test case, the first line contains two integers n ($1 \leq n \leq 100000$), q ($0 \leq q \leq 100000$).

In the following n -1 lines, the i-th line contains two integers $u_i,v_i (1\leq u_i,v_i \leq n)$ indicating there is an edge between $u_i$i and $v_i$ in the tree.

In the next q lines, the i-th line first comes with an integer $m_i (1 \leq m_i \leq 100000)$ indicating the number of vertices in the query set.Then comes with mi different integers, indicating the nodes in the query set.

It is guaranteed that $\sum^q_{i=1} m_i \leq 100000$.

It is also guaranteed that the number of test cases in which $n \geq 1000$  or $\sum_{i=1}^{q} m_i \geq 1000$ is no more than 10.
输出解释
For each test case, first output one line "Case #x:", where x is the case number (starting from 1).

Then q lines follow, i-th line contains an integer indicating the size of the auxiliary set for each query.
输入样例
1
6 3
6 4
2 5
5 4
1 5
5 3
3 1 2 3
1 5
3 3 1 4
输出样例
Case #1:
3
6
3
提示


For the query {1,2, 3}:
•node 4, 5, 6 are important nodes For the query {5}:
•node 1,2, 3, 4, 6 are important nodes
•node 5 is the lea of node 4 and node 3 For the query {3, 1,4}:
• node 2, 5, 6 are important nodes 
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5927

最后修改于 2020-10-25T23:26:48+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
9000/4500MS(Java/Others) 65536/65536K(Java/Others)