#P10717. 【MX-X1-T5】「KDOI-05」简单的树上问题

    ID: 11690 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>O2优化容斥原理快速沃尔什变换 FWT状压 DP梦熊比赛

【MX-X1-T5】「KDOI-05」简单的树上问题

Background

Original problem link: https://oier.team/problems/X1E.

Problem Description

Xiao S has a tree with nn nodes. Each node has a light bulb.

Xiao S decides to perform kk flashing operations. When performing a flashing operation, he sends one flashing command to each light bulb using the computer host.

However, Xiao S's light bulbs are of poor quality, and only some of them can receive Xiao S's flashing command. Specifically, the light bulb on node jj has probability pi,jp_{i,j} to receive Xiao S's ii-th flashing operation.

Fortunately, Xiao S's different light bulbs can pass information to each other. Specifically, if a light bulb lies on the shortest path in the tree between two light bulbs that have received the information, then this light bulb can also perform the flashing operation (of course, the light bulbs that received the information will perform the flashing operation).

Define the beauty of light bulb ii as ai,Sa_{i,S}, where SS is the set of operations that this light bulb performs.

Define the beauty of the whole tree as the product of the beauty of all light bulbs. Find the expected beauty of the whole tree, modulo 998244353998244353.

Input Format

The first line contains two positive integers n,kn,k, representing the number of nodes of the tree and the number of operations.

The next n1n-1 lines each contain two positive integers u,vu,v, representing an edge (u,v)(u,v) of the tree.

The next kk lines each contain nn non-negative integers. The jj-th number in the ii-th line represents pi,jp_{i,j} modulo 998244353998244353.

The next nn lines each contain 2k2^k non-negative integers. The (i=1k2i1[iS])+1(\sum_{i=1}^k2^{i-1}[i\in S])+1-th number in the ii-th line represents ai,Sa_{i,S}. You can understand it as: in ai,ja_{i,j}, the xx-th binary bit (from low to high) of j1j-1 indicates whether operation xx is included.

Output Format

One line with one non-negative integer, representing the expected beauty of the whole tree modulo 998244353998244353.

3 1
1 2
2 3
499122177 499122177 499122177
1 2
1 3
1 4
499122186
10 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
1 1 4 5
1 4 1 9
1 9 8 1
0 1 1 4
5 1 4 1
9 1 9 8
1 0 9 9
8 2 4 4
3 5 3 1
2 3 4 5
497209006

Hint

[Sample Explanation #1]

::cute-table

Set of bulbs that receive information Bulb beauty Tree beauty
\varnothing 1,1,11,1,1 11
{1}\{1\} 2,1,12,1,1 22
{2}\{2\} 1,3,11,3,1 33
{3}\{3\} 1,1,41,1,4 44
{1,2}\{1,2\} 2,3,12,3,1 66
{1,3}\{1,3\} 2,3,42,3,4 2424
{2,3}\{2,3\} 1,3,41,3,4 1212
{1,2,3}\{1,2,3\} 2,3,42,3,4 2424

Therefore, the expected beauty is 1+2+3+4+6+24+12+248=192\frac{1+2+3+4+6+24+12+24}{8}=\frac{19}{2}, and modulo 998244353998244353 it equals 499122186499122186.

[Constraints]

This problem uses bundled testdata.

::cute-table{tuack}

Subtask ID Score nn\leq kk\leq Special property
11 55 2020 11 None
22 1010 100100 22 Edge ii connects nodes ii and i+1i+1
33 55 88 pi,j=0p_{i,j}=0 or pi,j=1p_{i,j}=1
44 ai,S=[S={1,2,,k}]a_{i,S}=[S=\{1,2,\dots,k\}]
55 2020 Edge ii connects nodes ii and i+1i+1
66 1515 66 None
77 77
88 1010 5050 88
99 1515 100100

For 100%100\% of the data: 1n1001\leq n\leq100, 1k81\leq k\leq8, 1u,vn1\leq u,v\leq n. It is guaranteed that the given graph is a tree, and all other input values are integers in [0,998244353)[0,998244353).

Translated by ChatGPT 5