Complete Tripartite

시간 제한2초메모리 제한1024 MB

요약
무향 그래프의 정점을 세 개의 비어 있지 않은 그룹으로 나누어, 모든 간선이 그룹 사이에만 있고 그룹 안에는 없도록 만들 수 있는지 판정한다.
난이도

보통10점 중 6점

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

문제

You have a simple undirected graph consisting of nn vertices and mm edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.

Let's make a definition.

Let v_1v\_1 and v_2v\_2 be two some nonempty subsets of vertices that do not intersect. Let f(v_1,v_2)f(v\_{1}, v\_{2}) be true if and only if all the conditions are satisfied:

  1. There are no edges with both endpoints in vertex set v_1v\_1.
  2. There are no edges with both endpoints in vertex set v_2v\_2.
  3. For every two vertices xx and yy such that xx is in v_1v\_1 and yy is in v_2v\_2, there is an edge between xx and yy.

Create three vertex sets (v_1v\_{1}, v_2v\_{2}, v_3v\_{3}) which satisfy the conditions below;

  1. All vertex sets should not be empty.
  2. Each vertex should be assigned to only one vertex set.
  3. f(v_1,v_2)f(v\_{1}, v\_{2}), f(v_2,v_3)f(v\_{2}, v\_{3}), f(v_3,v_1)f(v\_{3}, v\_{1}) are all true.

Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.

입력

The first line contains two integers nn and mm (3≤n≤1053 \le n \le 10^{5}, 0≤m≤min(3⋅105,n(n−1)2)0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})) --- the number of vertices and edges in the graph.

The ii-th of the next mm lines contains two integers a_ia\_{i} and b_ib\_{i} (1≤a_i<b_i≤n1 \le a\_{i} \lt b\_{i} \le n) --- it means there is an edge between a_ia\_{i} and b_ib\_{i}. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.

출력

If the answer exists, print nn integers. ii-th integer means the vertex set number (from 11 to 33) of ii-th vertex. Otherwise, print −1-1.

If there are multiple answers, print any.

힌트

In the first example, if v_1=1v\_{1} = \\{ 1 \\}, v_2=2,3v\_{2} = \\{ 2, 3 \\}, and v_3=4,5,6v\_{3} = \\{ 4, 5, 6 \\} then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well.

In the second example, it's impossible to make such vertex sets.

예제2

  1. 예제 1

    입력
    6 11
    1 2
    1 3
    1 4
    1 5
    1 6
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6
    
    예상 출력
    1 2 2 3 3 3
    
  2. 예제 2

    입력
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    
    예상 출력
    -1