#P5405. [CTS2019] 氪金手游

[CTS2019] 氪金手游

Description

Student Xiao Liu is a boy who likes pay-to-win mobile games.

He recently got addicted to a new game whose content is to keep drawing cards. It is known that:

  • There are NN types of cards in the pool. The ii-th type of card has a weight WiW_i. Xiao Liu does not know the exact value of WiW_i, but by talking with other players he learned that WiW_i follows a distribution.
  • Specifically, for each ii, Xiao Liu knows three parameters pi,1,pi,2,pi,3p_{i,1}, p_{i,2}, p_{i,3}. The value of WiW_i is jj with probability pi,jp_{i,j}. It is guaranteed that pi,1+pi,2+pi,3=1p_{i,1} + p_{i,2} + p_{i,3} = 1.

Xiao Liu starts playing the game. Each time, he pays 1 yuan to draw one card. The probability of drawing card ii is:

WijWj\frac{W_i}{\sum_j W_j}

Xiao Liu will keep drawing cards until he has collected all NN types of cards.

After the drawing ends, the server records the time TiT_i when Xiao Liu gets each card for the first time. The game company sets up an easter egg: the company prepares N1N - 1 ordered pairs (ui,vi)(u_i, v_i). If for every ii, the condition Tui<TviT_{u_i} < T_{v_i} holds, then the company will consider Xiao Liu extremely lucky and will give him a cabinet of figurines as the lucky grand prize.

To reduce the chance of winning, these (ui,vi)(u_i, v_i) satisfy the following property: for any S{1,2,,N}\varnothing \ne S \subsetneq \{1,2,\ldots,N\}, there always exists some (ui,vi)(u_i, v_i) such that uiS,viSu_i \in S, v_i \notin S or uiS,viSu_i \notin S, v_i \in S.

Please compute the probability that Xiao Liu can get the lucky grand prize. It is guaranteed that the result is a rational number. Output the result modulo 998244353998244353.

Input Format

The first line contains an integer NN, the number of card types.

The next NN lines each contain three integers ai,1,ai,2,ai,3a_{i,1}, a_{i,2}, a_{i,3}, and the probabilities in the statement are given by $p_{i,j} = \frac{a_{i,j}}{a_{i,1} + a_{i,2} + a_{i,3}}$.

The next N1N - 1 lines each contain two integers ui,viu_i, v_i, describing an ordered pair (see the statement for its meaning).

Output Format

Output one integer in one line, the required probability modulo 998244353998244353.

2
0 0 1
1 1 0
1 2
524078286

Hint

Explanation of Sample 1

W2W_2 is 11 or 22 with probability 12\frac 12:

  • If W2=1W_2 = 1, then the probability that T1<T2T_1 < T_2 is 34\frac 34.
  • Otherwise, if W2=2W_2 = 2, then the probability that T1<T2T_1 < T_2 is 35\frac 35.

Combining all cases, the answer is $\frac 12\left(\frac 34 + \frac 35\right) = \frac{27}{40}$. You can verify that its value modulo 998244353998244353 is indeed the given output.

Testdata Constraints

For all testdata, it is guaranteed that N1000N \le 1000 and ai,j106a_{i,j} \le 10^6.

  • 2020 points: N15N \le 15.
  • 1515 points: N200N \le 200, and every constraint satisfies uivi=1|u_i−v_i|=1.
  • 2020 points: N1000N \le 1000, and every constraint satisfies uivi=1|u_i−v_i|=1.
  • 1515 points: N200N \le 200.
  • 3030 points: no special constraints.

Translated by ChatGPT 5