| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 2048 MB | 39 | 15 | 14 | 50.000% |
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,\dots ,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.
Figure 1: Illustration of the second sample case. The number written just outside the vertex corresponds to the colour it receives corresponding to the output for that sample case.
The first line of input contains two integers $N$ (1ドル≤N≤10^5$) and $M$ (0ドル≤M≤10^5$). The next $M$ lines each contain two integers $u$ and $v$ (1ドル≤u,v≤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 $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$.
3 3 1 2 2 3 3 1
2 3 1
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
5 4 1 2 1 3 2 4 2 5
1 2 2 1 1
University > University of Alberta Programming Contest > UAPC 2024 > Division 1 J번
University > University of Alberta Programming Contest > UAPC 2024 > Division 2 J번