#P17891. [ICPC 2026 Nanchang I] Eating Cherries
[ICPC 2026 Nanchang I] Eating Cherries
Problem Description
Jiangqiao loves eating cherries! Before the cherries ripened, he had already arrived at the cherry tree...
A cherry tree consists of nodes (numbered to ) and branches, which connect all the nodes together.
Jiangqiao classifies the cherries on the whole cherry tree into types (numbered to ) based on size, color, sweetness, etc., where node has types of cherries.
A main branch is the path from the root node to a certain leaf node without repeating any node.
That is, for root node , the main branch from to a leaf node is a node sequence , where node is connected to node () by a branch, and whenever .
A leaf node refers to a node that is connected to only one branch with other nodes. Specifically, the root node is not a leaf node.
Obviously, for each leaf node, the main branch from the root to it is uniquely determined.
Jiangqiao can cast magic. Each spell can choose a leaf node and arbitrarily change the cherry types and the number of types on that node (including making it cherry-free).
He wants to know, for each node serving as the root, the minimum number of spells needed so that the set of cherry types on every main branch is the same.
Input Format
The first line contains two integers and (, ) --- the number of nodes and the number of cherry types.
Each of the next lines contains two integers and (, ) --- a branch on the tree.
Each of the next lines describes a node. The -th of these lines starts with a non-negative integer () --- the number of cherry types at node . If , it is followed by distinct integers () --- the cherry types.
It is guaranteed that all nodes are connected by the branches.
Output Format
A single line containing non-negative integers, where the -th integer is the answer when node is the root.
5 2
1 2
2 3
2 4
4 5
1 1
1 1
2 1 2
0
1 1
1 1 0 1 1