Problem F
Triangle Trees
A triangle tree is an undirected graph in which every cycle contains exactly three edges. Recall that a cycle is a sequence of at least $3$ distinct vertices $v_1, v_2, \ldots , v_ k$ such that there is an edge between $v_ i$ and $v_{i+1}$ for $i=1,\dots ,k-1$ and there is also an edge between $v_ k$ and $v_1$.
A colouring of a graph is an assignment of colours to the vertices such that the two endpoints of each edge of the graph receive different colours. Given a triangle tree, your task is to find a colouring which uses the smallest possible number of colours.
Input
The first line of input contains two integers $N$ ($1\le N \le 10^5$) and $M$ ($0\le M \le 10^5$). The next $M$ lines each contain two integers $u$ and $v$ ($1\le u,v\le N$) indicating that the graph contains an edge between $u$ and $v$. It is guaranteed that $u\ne v$, all edges are unique, and that the graph is indeed a triangle tree.
Output
Output $N$ integers indicating the colours of vertices $1,2,\dots ,N$ in order. If you used $k$ colours, the integers should be from the set $\{ 1,2,\dots ,k\} $. If there are multiple valid colourings, you may output any one of them. Recall the goal is to output such a colouring using the fewest colours possible, i.e. minimize $k$.
Sample Input 1 | Sample Output 1 |
---|---|
3 3 1 2 2 3 3 1 |
2 3 1 |
Sample Input 2 | Sample Output 2 |
---|---|
7 8 1 2 1 7 2 7 3 4 3 7 4 7 5 7 6 7 |
3 2 3 2 2 2 1 |
Sample Input 3 | Sample Output 3 |
---|---|
5 4 1 2 1 3 2 4 2 5 |
1 2 2 1 1 |