#P5643. [PKUWC2018] 随机游走

[PKUWC2018] 随机游走

Description

Given a tree with nn nodes, you start from node xx. Each time, you randomly choose an edge adjacent to the current node with equal probability and walk along it.

There are QQ queries. In each query, you are given a set SS. Starting from xx, you keep doing the random walk until every node in SS has been visited at least once. Find the expected number of steps.

In particular, node xx (the starting node) is considered to have been visited once at the beginning.

Output the answer modulo 998244353998244353.

Input Format

The first line contains three positive integers n,Q,xn, Q, x.

The next n1n - 1 lines each contain two positive integers (u,v)(u, v) describing an edge of the tree.

The next QQ lines describe the queries. Each line starts with an integer kk denoting the size of the set, followed by kk pairwise distinct integers denoting the set SS.

Output Format

Output QQ 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 20%20\% of the testdata, 1n,Q51 \leq n, Q \leq 5.

For another 10%10\% of the testdata, the given tree is a chain.

For another 10%10\% of the testdata, for all queries k=1k = 1.

For another 30%30\% of the testdata, 1n101 \leq n \leq 10 and Q=1Q = 1.

For 100%100\% of the testdata, 1n181 \leq n \leq 18, 1Q50001 \leq Q \leq 5000, and 1kn1 \leq k \leq n.

Translated by ChatGPT 5