#P3914. 染色计数
染色计数
Description
There is a tree with nodes, numbered . You need to color it so that adjacent nodes have different colors. There are colors, numbered . Each node may be colored with a subset of the colors. Compute the number of different valid colorings modulo .
Input Format
The first line contains two integers .
Then follow lines. The -th line describes the colors allowed for node : the first integer is the number of allowed colors, followed by integers giving the allowed color indices.
Finally, the last lines each contain two integers , indicating an edge .
Output Format
Output one integer, the number of valid colorings modulo .
2 2
1 1
2 1 2
1 2
1
Hint
• For 30% of the testdata, .
• For 60% of the testdata, .
• For 100% of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号