#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100007];
map<vector<int>,int>mp;
int main(){
int n,m;
scanf("%d%d",&n,&m);
int u,v;
for(int i=1;i<=m;++i){
scanf("%d%d",&u,&v);
adj[u].push_back(v);
adj[v].push_back(u);
}
int type=0;
for(int i=1;i<=n;++i){
if(!adj[i].size()||type>3){//独立点和其他集合的点之间不存在边或者集合多于3个都是-1情况
printf("-1");
return 0;
}
sort(adj[i].begin(),adj[i].end());//全部排为升序才能mp寻值
if(!mp[adj[i]])//与i相连的这组点第一次出现
mp[adj[i]]=++type;//将它们分到一个集合
}
if(type!=3)
printf("-1");
else
for(int i=1;i<=n;++i)
printf("%d ",mp[adj[i]]);
return 0;
}
相关文章
- 02-28Codeforces Round #455 (Div. 2) D题(花了一个早自习补了昨晚的一道模拟QAQ)
- 02-28Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
- 02-28Codeforces Round #633 (Div. 2) D. Edge Weight Assignment
- 02-28Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
- 02-28Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins
- 02-28Educational Codeforces Round 115 (Rated for Div. 2) A-D
- 02-28Codeforces Round #364 (Div. 2) D. As Fast As Possible
- 02-28Codeforces Round #244 (Div. 2)D (后缀自己主动机)
- 02-28Codeforces Round #746 (Div. 2) C - Bakry and Partitioning(dfs 异或技巧 思维)
- 02-28Codeforces Round #530 (Div. 2) A,B,C,D