#P5643. [PKUWC2018] 随机游走
[PKUWC2018] 随机游走
Description
Given a tree with nodes, you start from node . Each time, you randomly choose an edge adjacent to the current node with equal probability and walk along it.
There are queries. In each query, you are given a set . Starting from , you keep doing the random walk until every node in has been visited at least once. Find the expected number of steps.
In particular, node (the starting node) is considered to have been visited once at the beginning.
Output the answer modulo .
Input Format
The first line contains three positive integers .
The next lines each contain two positive integers describing an edge of the tree.
The next lines describe the queries. Each line starts with an integer denoting the size of the set, followed by pairwise distinct integers denoting the set .
Output Format
Output lines. Each line contains a non-negative integer representing the answer.
3 5 1
1 2
2 3
1 1
1 3
2 2 3
3 1 2 3
2 1 2
0
4
4
4
1
Hint
For of the testdata, .
For another of the testdata, the given tree is a chain.
For another of the testdata, for all queries .
For another of the testdata, and .
For of the testdata, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号