Under construction

Still being built. Things may change

Complete Tripartite

Interview

Time limit2sMemory limit1024 MB

Summary
Given an undirected graph, split the vertices into three nonempty sets, each independent, with every pair of sets fully joined by edges, or report -1.
Level

Medium5 of 10

Topics
Hash map, Graph, Implementation
Solved
No attempts yet

Problem

You are given a simple undirected graph with nn vertices and mm edges. The graph has no self-loops, and there is at most one edge between any pair of vertices. The graph may be disconnected.

For two nonempty, disjoint vertex sets v1v_1 and v2v_2, define f(v1,v2)f(v_1, v_2) as true if and only if all of the following hold:

  1. No edge has both endpoints in v1v_1.
  2. No edge has both endpoints in v2v_2.
  3. For every vertex xx in v1v_1 and every vertex yy in v2v_2, there is an edge between xx and yy.

Create three vertex sets v1v_1, v2v_2, v3v_3 that satisfy the following:

  1. All three sets are nonempty.
  2. Each vertex belongs to exactly one of the sets.
  3. f(v1,v2)f(v_1, v_2), f(v2,v3)f(v_2, v_3), and f(v3,v1)f(v_3, v_1) are all true.

Determine whether such sets exist. If they do, print the set number of each vertex.

Input

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 \min(3 \cdot 10^{5}, \frac{n(n-1)}{2})), the number of vertices and edges. Each of the next mm lines contains two integers aia_i and bib_i (1≤ai<bi≤n1 \le a_i < b_i \le n), meaning there is an edge between aia_i and bib_i. The graph has no self-loops, and there is at most one edge between any pair of vertices.

Output

If a valid assignment exists, print nn integers. The ii-th integer is the set number (from 1 to 3) of vertex ii. Otherwise, print -1. If there are multiple answers, print any of them.

Hint

In the first example, v1={1}v_1 = \{1\}, v2={2,3}v_2 = \{2, 3\}, and v3={4,5,6}v_3 = \{4, 5, 6\} satisfy all conditions. You may assign the vertices differently. Other answers such as "2 3 3 1 1 1" are also accepted.

In the second example, no valid sets can be made.

Examples2

  1. Example 1

    Input
    6 11
    1 2
    1 3
    1 4
    1 5
    1 6
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6
    
    Expected output
    1 2 2 3 3 3
    
  2. Example 2

    Input
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    
    Expected output
    -1