#P6478. [NOI Online #2 提高组] 游戏
[NOI Online #2 提高组] 游戏
Background
1s 512M
Problem Description
Player A and Player B are playing a game. There is a rooted tree with nodes (nodes are numbered from ). The root is node . At the beginning, each player owns nodes.
In each round, both players must choose one node that they own and that has not been chosen before. If the opponent’s chosen node is in the subtree of your chosen node, then you win this round. If your chosen node is in the subtree of the opponent’s chosen node, then you lose this round. In all other cases, the round is a draw. The game lasts for rounds in total.
As a spectator, you only want to know, when they choose nodes uniformly at random, the expected round number at which the first non-draw round appears.
To compute this expectation, you decide to compute, for , the number of cases where the number of non-draw rounds is . Two cases are considered different if and only if there exists a node owned by Player A such that, in the round where is chosen by Player A, the node chosen by Player B is different in the two cases.
Since the total number of cases may be very large, you only need to output the result modulo .
Input Format
The first line contains a positive even integer , denoting the number of nodes in the tree.
The second line contains a 01 string of length . The -th character is if node is owned by Player A, otherwise it is owned by Player B. It is guaranteed that the number of and the number of are the same.
The next lines each contain two positive integers , , denoting an edge in the tree.
Output Format
There are lines in total, each containing one integer. The integer on the -th line represents the answer when .
8
10010011
1 2
1 3
2 4
2 5
5 6
3 7
3 8
0
10
10
4
0
Hint
| Test Point ID | Special Property | |
|---|---|---|
| 1 4 | None | |
| 5 8 | ||
| 9 10 | The tree degenerates into a chain | |
| 11 12 | None | |
| 13 14 | ||
| 15 16 | The tree degenerates into a chain | |
| 17 20 | None |
Translated by ChatGPT 5