#P15446. 「IXOI R1」BA BA 博弈
「IXOI R1」BA BA 博弈
Description
A and B are playing a game on a tree.
Specifically, you are given a tree rooted at node .
B starts the game from the root. In each round, he must choose to move to one of the children of the current node. He has no knowledge about the structure of the tree, which means he only knows the information about the children of the current node.
A starts from any leaf node and in each round, A can move to any leaf node. A knows the structure of the tree as well as that B starts from the root node. During the game, he doesn't know the position of B. But before each round begins, he can use a skill to know where B is.
Now the two start the game. In each round, the process is as follows:
- A decides whether to use the skill to know the position of B.
- A and B move at the same time.
- If the node at which B stays is a leaf, then: if A is at the same node, A wins; otherwise B wins.
The goal of A is to minimize the number of times using skills while maximizing the probability of winning. The goal of B is to maximize the probability of winning.
A and B are extremely intelligent, and both of them employ the optimal strategy.
Both A and B are aware of each other's situations and the game rules, and they also know that the other one is aware of their situations and the game rules as well. That is to say, the game rules and the situations of both parties are common knowledge to both parties.
Calculate the expected number of times that A uses the skill, and print it modulo .
Note: If you are not familiar with the relevant knowledge of Nash equilibrium, you can assume that each time B will randomly choose one of the child nodes with equal probability.
Input Format
The first line contains a positive integer : the number of nodes of the tree.
Next lines, each contains two integers and , representing an edge on the tree.
Output Format
Output one line, a single integer, representing the expected number of times that A uses the skill modulo .
6
1 2
1 3
2 4
2 5
3 6
1
Hint
Example Explanation
One of A's optimal strategies is to use the skill at the beginning of the second round to check B's position and determine whether B is at node or node . If B is at node , then A should randomly choose one of nodes or to wait, and the winning probability is . If B is at node , then A should wait at node , the expected number of skill uses is . It can be proved that no better strategy exists.
Constraints
This problem uses bundled testing.
| Subtask Id | Special property | Points | |
|---|---|---|---|
| No | |||
| A | |||
| B | |||
| No |
Special property A: .
Special property B: .
For all data, it is guaranteed that:
and the given graph is a tree.
京公网安备 11011102002149号