Triangle Trees

시간 제한4초메모리 제한2048 MB

요약
모든 사이클이 삼각형인 무향 그래프, 즉 삼각형 트리를 최소 개수의 색으로 칠하는 문제입니다.
난이도

보통10점 중 7점

유형
그래프, DFS, 그리디, 구현
정답자
아직 제출이 없습니다

문제

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 33 distinct vertices v_1,v_2,…,v_kv\_1,v\_2,\dots ,v\_k such that there is an edge between v_iv\_i and v_i+1v\_{i+1} for i=1,…,k−1i=1,\dots ,k-1 and there is also an edge between v_kv\_k and v_1v\_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 NN (1≤N≤1051≤N≤10^5) and MM (0≤M≤1050≤M≤10^5). The next MM lines each contain two integers uu and vv (1≤u,v≤N1≤u,v≤N) indicating that the graph contains an edge between uu and vv. It is guaranteed that u≠vu \ne v, all edges are unique, and that the graph is indeed a triangle tree.

출력

Output NN integers indicating the colours of vertices 1,2,…,N1,2,\dots ,N in order. If you used kk colours, the integers should be from the set 1,2,…,k\\{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 kk.

예제3

  1. 예제 1

    입력
    3 3
    1 2
    2 3
    3 1
    
    예상 출력
    2 3 1
    
  2. 예제 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
    
  3. 예제 3

    입력
    5 4
    1 2
    1 3
    2 4
    2 5
    
    예상 출력
    1 2 2 1 1