#P6478. [NOI Online #2 提高组] 游戏

    ID: 7249 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学2020树形 DP排列组合NOI Online

[NOI Online #2 提高组] 游戏

Background

1s 512M

Problem Description

Player A and Player B are playing a game. There is a rooted tree with n=2mn = 2m nodes (nodes are numbered from 1n1 \sim n). The root is node 11. At the beginning, each player owns mm 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 mm 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 k=0,1,2,,mk = 0, 1, 2, \cdots, m, the number of cases where the number of non-draw rounds is kk. Two cases are considered different if and only if there exists a node xx owned by Player A such that, in the round where xx 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 998244353998244353.

Input Format

The first line contains a positive even integer nn, denoting the number of nodes in the tree.

The second line contains a 01 string of length nn. The ii-th character is 00 if node ii is owned by Player A, otherwise it is owned by Player B. It is guaranteed that the number of 00 and the number of 11 are the same.

The next n1n - 1 lines each contain two positive integers uu, vv, denoting an edge in the tree.

Output Format

There are n2+1\frac{n}{2} + 1 lines in total, each containing one integer. The integer on the ii-th line represents the answer when k=i1k = i - 1.

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 n=n = Special Property
1 \sim 4 2020 None
5 \sim 8 5050
9 \sim 10 300300 The tree degenerates into a chain
11 \sim 12 None
13 \sim 14 500500
15 \sim 16 50005000 The tree degenerates into a chain
17 \sim 20 None

Translated by ChatGPT 5