Codeforces Round 411 (Div. 2)
E
Ice cream coloring
Codeforces
未评级
原题
← DF →
翻译中…

Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?"

翻译中…

We have a tree $*T*$ with $*n*$ vertices and $*m*$ types of ice cream numerated from $1$ to $*m*$. Each vertex $*i*$ has a set of $*s*_{*i*}$ types of ice cream. Vertices which have the $*i*$-th ($1 ≤ *i* ≤ *m*$) type of ice cream form a connected subgraph. We build a new graph $*G*$ with $*m*$ vertices. We put an edge between the $*v*$-th and the $*u*$-th ($1 ≤ *u*, *v* ≤ *m*$, $*u* ≠ *v*$) vertices in $*G*$ if and only if there exists a vertex in $*T*$ that has both the $*v*$-th and the $*u*$-th types of ice cream in its set. The problem is to paint the vertices of $*G*$ with minimum possible number of colors in a way that no adjacent vertices have the same color.

翻译中…

Please note that we consider that empty set of vertices form a connected subgraph in this problem.

翻译中…

As usual, Modsart don't like to abandon the previous problem, so Isart wants you to solve the new problem.

翻译中…

Input

翻译中…

The first line contains two integer $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 3·10^{5}$) — the number of vertices in $*T*$ and the number of ice cream types.

翻译中…

$*n*$ lines follow, the $*i*$-th of these lines contain single integer $*s*_{*i*}$ ($0 ≤ *s*_{*i*} ≤ 3·10^{5}$) and then $*s*_{*i*}$ distinct integers, each between $1$ and $*m*$ — the types of ice cream in the $*i*$-th vertex. The sum of $*s*_{*i*}$ doesn't exceed $5·10^{5}$.

翻译中…

$*n* - 1$ lines follow. Each of these lines describes an edge of the tree with two integers $*u*$ and $*v*$ ($1 ≤ *u*, *v* ≤ *n*$) — the indexes of connected by this edge vertices.

翻译中…

Output

翻译中…

Print single integer $*c*$ in the first line — the minimum number of colors to paint the vertices in graph $*G*$.

翻译中…

In the second line print $*m*$ integers, the $*i*$-th of which should be the color of the $*i*$-th vertex. The colors should be between $1$ and $*c*$. If there are some answers, print any of them.

翻译中…

Note

翻译中…

In the first example the first type of ice cream is present in the first vertex only, so we can color it in any color. The second and the third ice cream are both presented in the second vertex, so we should paint them in different colors.

翻译中…

In the second example the colors of the second, the fourth and the fifth ice cream should obviously be distinct.

翻译中…

样例

Input #1
3 3
1 1
2 2 3
1 2
1 2
2 3
Output #1
2
1 1 2
InputCopy OutputCopy
Input #2
4 5
0
1 1
1 3
3 2 4 5
2 1
3 2
4 3
Output #2
3
1 1 1 2 3
InputCopy OutputCopy
题目信息
题号
805E
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。