#abc314f. F - A Certain Game

F - A Certain Game

Score : 475475 points

问题描述

设有 NN 名玩家,编号分别为 player 11、player 22、...、player NN,参加一场游戏锦标赛。在比赛开始前,每位玩家各自组成一个单人队伍,因此总共有 NN 支队伍。

锦标赛共包含 N1N-1 场比赛。每场比赛中,会选取两支不同的队伍进行对决。一支队伍先手,另一支队伍后手。每场比赛将会有且仅有一支队伍获胜。具体来说,对于每场第 i=1,2,,N1i = 1, 2, \ldots, N-1 的比赛,其过程如下:

  • 拥有玩家 pip_i 的队伍先手,拥有玩家 qiq_i 的队伍后手。
  • 设第一队和第二队的队员人数分别为 aabb,则第一队获胜的概率为 aa+b\frac{a}{a+b},第二队获胜的概率为 ba+b\frac{b}{a+b}
  • 然后,两支队伍合并为一支队伍。

每场比赛的结果相互独立。

对于这 NN 名玩家中的每一位,请输出在整个锦标赛期间,该玩家所在队伍预期获胜的次数对 998244353998244353 取模后的结果。

如何打印模 998244353998244353 下的期望值

可以证明所求的期望值始终是理性的。同时,本问题的约束条件保证了如果所求期望值表示为不可约分数 yx\frac{y}{x},则 xx 不会被 998244353998244353 整除。

现在存在一个唯一的整数 zz,满足 0z9982443520 \le z \le 998244352,且 xzy(mod998244353)xz \equiv y \pmod{998244353}。请报告这个 zz 值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

NN players, player 11, player 22, ..., player NN, participate in a game tournament. Just before the tournament starts, each player forms a one-person team, so there are NN teams in total.

The tournament has a total of N1N-1 matches. In each match, two different teams are chosen. One team goes first, and the other goes second. Each match will result in exactly one team winning. Specifically, for each i=1,2,,N1i = 1, 2, \ldots, N-1, the ii-th match proceeds as follows.

  • The team with player pip_i goes first, and the team with player qiq_i goes second.
  • Let aa and bb be the numbers of players in the first and second teams, respectively. The first team wins with probability aa+b\frac{a}{a+b}, and the second team wins with probability ba+b\frac{b}{a+b}.
  • Then, the two teams are combined into a single team.

The result of each match is independent of those of the others.

For each of the NN players, print the expected number of times the team with that player wins throughout the tournament, modulo 998244353998244353.

How to print an expected value modulo 998244353998244353

It can be proved that the sought expected value is always rational. Also, the constraints of this problem guarantee that if the sought expected value is expressed as an irreducible fraction yx\frac{y}{x}, then xx is not divisible by 998244353998244353.

Now, there is a unique integer zz between 00 and 998244352998244352, inclusive, such that xzy(mod998244353)xz \equiv y \pmod{998244353}. Report this zz.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1pi,qiN1 \leq p_i, q_i \leq N
  • Just before the ii-th match, player pip_i and player qiq_i belong to different teams.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

p1p_1 q1q_1

p2p_2 q2q_2

\vdots

pN1p_{N-1} qN1q_{N-1}

Output

For each i=1,2,,Ni = 1, 2, \ldots, N, print EiE_i, the expected number, modulo 998244353998244353, of times the team with player ii wins throughout the tournament, separated by spaces, in the following format:

E1E_1 E2E_2 \ldots ENE_N

Sample Input 1

5
1 2
4 3
5 3
1 4

Sample Output 1

698771048 698771048 964969543 964969543 133099248

We call a team formed by player x1x_1, player x2x_2, \ldots, player xkx_k as team {x1,x2,,xk}\lbrace x_1, x_2, \ldots, x_k \rbrace.

  • The first match is played by team {1}\lbrace 1 \rbrace, with player 11, and team {2}\lbrace 2 \rbrace, with player 22. Team {1}\lbrace 1 \rbrace wins with probability 12\frac{1}{2}, and team {2}\lbrace 2 \rbrace wins with probability 12\frac{1}{2}. Then, the two teams are combined into a single team {1,2}\lbrace 1, 2 \rbrace.
  • The second match is played by team {4}\lbrace 4 \rbrace, with player 44, and team {3}\lbrace 3 \rbrace, with player 33. Team {4}\lbrace 4 \rbrace wins with probability 12\frac{1}{2}, and team {3}\lbrace 3 \rbrace wins with probability 12\frac{1}{2}. Then, the two teams are combined into a single team {3,4}\lbrace 3, 4 \rbrace.
  • The third match is played by team {5}\lbrace 5 \rbrace, with player 55, and team {3,4}\lbrace 3, 4 \rbrace, with player 33. Team {5}\lbrace 5 \rbrace wins with probability 13\frac{1}{3}, and team {3,4}\lbrace 3, 4 \rbrace wins with probability 23\frac{2}{3}. Then, the two teams are combined into a single team {3,4,5}\lbrace 3, 4, 5 \rbrace.
  • The fourth match is played by team {1,2}\lbrace 1, 2 \rbrace, with player 11, and team {3,4,5}\lbrace 3, 4, 5 \rbrace, with player 44. Team {1,2}\lbrace 1, 2 \rbrace wins with probability 25\frac{2}{5}, and team {3,4,5}\lbrace 3, 4, 5 \rbrace wins with probability 35\frac{3}{5}. Then, the two teams are combined into a single team {1,2,3,4,5}\lbrace 1, 2, 3, 4, 5 \rbrace.

The expected numbers of times the teams with players 1,2,3,4,51, 2, 3, 4, 5 win throughout the tournament, E1,E2,E3,E4,E5E_1, E_2, E_3, E_4, E_5, are $\frac{9}{10}, \frac{9}{10}, \frac{53}{30}, \frac{53}{30}, \frac{14}{15}$, respectively.

Sample Input 2

15
9 2
8 10
13 6
12 11
7 10
4 10
14 2
5 4
1 15
15 2
6 9
8 11
6 3
2 8

Sample Output 2

43970290 310168785 806914186 501498951 950708909 272140427 335124893 168750835 310168785 168750835 280459129 280459129 272140427 476542843 43970290

update @ 2024/3/10 08:59:19