33OJ
登录 注册

#P17891. [ICPC 2026 Nanchang I] Eating Cherries

    ID: 20627 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>树形 DP江西位运算ICPC2026省赛/邀请赛状压 DP

[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 nn nodes (numbered 11 to nn) and n−1n - 1 branches, which connect all the nodes together.

Jiangqiao classifies the cherries on the whole cherry tree into mm types (numbered 11 to mm) based on size, color, sweetness, etc., where node ii has kik_i 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 uu, the main branch from uu to a leaf node vv is a node sequence [u=x0,x1,x2,…,xs=v][u = x_0, x_1, x_2, \ldots, x_s = v], where node xix_i is connected to node xi+1x_{i+1} (i<si < s) by a branch, and xi≠xjx_i \neq x_j whenever i≠ji \neq j.

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 1,2,...,n1,2,...,n 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 nn and mm (2≤n≤2×1052 \le n \le 2 \times 10^5, 1≤m≤61 \le m \le 6) --- the number of nodes and the number of cherry types.

Each of the next n−1n - 1 lines contains two integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \neq v_i) --- a branch on the tree.

Each of the next nn lines describes a node. The ii-th of these lines starts with a non-negative integer kik_i (0≤ki≤m0 \le k_i \le m) --- the number of cherry types at node ii. If ki>0k_i > 0, it is followed by kik_i distinct integers ti,1,ti,2,…,ti,kit_{i,1}, t_{i,2}, \ldots, t_{i,k_i} (1≤ti,j≤m1 \le t_{i,j} \le m) --- the cherry types.

It is guaranteed that all nodes are connected by the branches.

Output Format

A single line containing nn non-negative integers, where the ii-th integer is the answer when node ii 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