#P4321. 随机漫游
随机漫游
Description
Country H has cities.
In the next days, Xiao c will go to look for Xiao w, but Xiao c does not know the exact location of Xiao w, so Xiao c decides to randomly choose one road to walk each time until meeting Xiao w.
Xiao c knows that Xiao w can only be in one of the cities . Xiao c wants to know, in the worst case, the expected number of roads Xiao c needs to traverse before meeting Xiao w.
All edges in country H are undirected. Between any two cities, there is at most one road directly connecting them, and no road connects the same city to itself.
At any time, in country H there do not exist cities and such that cannot be reached from .
Input Format
The first line contains two positive integers , representing the number of cities and the number of edges in country H.
Lines 2 to each contain two positive integers , indicating there is a road between city and city .
Line contains one positive integer .
Lines to each contain positive integers: the first integer is , followed by distinct integers , and the last integer indicates the city where Xiao c is located.
Output Format
Output lines, each containing a single integer representing the answer.
If the expected value you compute is , where are coprime, then you should output an such that and . It can be proved that such an is unique.
3 2
1 2
2 3
3
2 1 2 1
3 1 2 3 1
1 3 1
1
4
4
Hint
The roads of country H form a chain, so in the worst case Xiao w is at the deepest node (taking Xiao c’s city as the root).
For the first day, Xiao c is in city 1, the deepest node is 2, city 1 can only reach city 2, and the expected number of roads to reach it is 1.
For the second day, Xiao c is in city 1, the deepest node is 3, and the computed expectation is 4 roads to reach it.
The third day is the same as the second day.
The worst case means going through all possible cities at least once.
Subtask 1: 10 points, .
Subtask 2: 15 points, .
Subtask 3: 15 points, .
Subtask 4: 10 points, , the graph is a chain.
Subtask 5: 10 points, , all are the same.
Subtask 6: 15 points, , .
Subtask 7: 15 points, , all are the same.
Subtask 8: 10 points, .
Constraints for all testdata: $1\leq N\leq 18, 1\leq M\leq 100000, 1\leq E\leq \frac{N(N-1)}{2}$.
Translated by ChatGPT 5
京公网安备 11011102002149号