D. Complete Tripartite

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 v1v1 and v2v2 be two some nonempty subsets of vertices that do not intersect. Let f(v1,v2)f(v1,v2) be true if and only if all the conditions are satisfied:

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

Create three vertex sets (v1v1, v2v2, v3v3) 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(v1,v2)f(v1,v2), f(v2,v3)f(v2,v3), f(v3,v1)f(v3,v1) are all true.

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

Input

The first line contains two integers nn and mm (3≤n≤1053≤n≤105, 0≤m≤min(3⋅105,n(n−1)2)0≤m≤min(3⋅105,n(n−1)2)) — the number of vertices and edges in the graph.

The ii-th of the next mm lines contains two integers aiai and bibi (1≤ai<bi≤n1≤ai<bi≤n) — it means there is an edge between aiai and bibi. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.

Output

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.

Examples

input

Copy


6 11 1 2 1 3 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6


output

Copy


1 2 2 3 3 3


input

Copy


4 6 1 2 1 3 1 4 2 3 2 4 3 4


output

Copy


-1


Note

In the first example, if v1={1}v1={1}, v2={2,3}v2={2,3}, and v3={4,5,6}v3={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.

Codeforces Round #589 (Div. 2) D. Complete Tripartite(巧妙的Hash)_i++

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

 


20.

OJ题号

链接:https://codeforces.com/contest/1228/problem/D 来源:Codeforces Round #589 (Div. 2)

简单题意

给一张n个点的无向图,无自环,不保证联通,问是否能三分这张图。对于每个集合的要求为,集合内部的点,两两之间不能有边相连,不同集合之间的点都需要有边相连。如果可以三分这张图,输出方案;如果不能,输出-1。

正解思路

这题首先分图有个特性,就是在一个集合的点周围连着点都是相同的,所以可以用Hash把一个点与周围其他点hash一下即可(具体看代码),最后有一个需要注意的地方是,如果一个点相邻节点哈希值为0,则不满足条件。

 

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
const int mod=1e9+7;
const int N=500005;
const ULL base=131;
ULL Hash[N];
ULL power[N];
void init()
{
	power[0]=1;
	for(int i=1;i<N;i++)
	{
		power[i]=power[i-1]*base;
	}
}


int main()
{
	init();
	int n,m;
	scanf("%d%d",&n,&m);
	
	int u,v;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		Hash[u]=(Hash[u]+power[v]);
		Hash[v]=(Hash[v]+power[u]);
	}
	
	unordered_map<ULL,int>mp;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(Hash[i]==0)
		{
			cnt=-1;
			break;
		}
		if(mp[Hash[i]]==0)
		{
			mp[Hash[i]]=++cnt;
		}
	}
	
	if(cnt!=3)
	{
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		printf("%d ",mp[Hash[i]]);
	
	
	
    return 0;
}