#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;
}

Codeforces Round #589 (Div. 2)D(思维,构造)的更多相关文章

  1. Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  2. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  3. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  4. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  5. Codeforces Round #589 (Div. 2) (e、f没写)

    https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...

  6. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  7. Codeforces Round #181 (Div. 2) A. Array 构造

    A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...

  8. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  9. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

随机推荐

  1. get_class和get_called_class的区别

    get_class ()       获取当前调用方法的类名get_called_class()    获取静态绑定后的类名 class Foo{ public function test() { v ...

  2. ASP学习笔记1

    一.变量 1.1 声明变量 dim name name="Donald Duck" response.write("My name is: " & na ...

  3. codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)

    题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...

  4. 395. 至少有K个重复字符的最长子串

    Q: A: 分治,对于字符串s的任何一个字符,如果它的频数(在s中出现的次数)小于k,则它一定不会出现在最后的结果里,也就是从它的位置一劈两半,考察左右.对于当前字符串s,我们先建立字典统计其中每种字 ...

  5. linux下建立多级文件目录

    linux下使用mkdir可以创建目录,使用mkdir -p参数就可以创建: mkdir -p /home/orale/duqiang1/duqiang2   如果父目录存在也不会报错.

  6. 威佐夫博奕(Wythoff Game)poj 1067

    有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 这种情况下是颇为复杂的.我们用(ak,bk)(ak ≤ bk ,k=0,1,2,…, ...

  7. React的React.createRef()/forwardRef()源码解析(三)

    1.refs三种使用用法 1.字符串 1.1 dom节点上使用 获取真实的dom节点 //使用步骤: 1. <input ref="stringRef" /> 2. t ...

  8. selenium配合phantomjs实现爬虫功能,并把抓取的数据写入excel

    # -*- coding: UTF-8 -*- ''' Created on 2016年5月13日 @author: csxie ''' import datetime from Base impor ...

  9. tensorflow按需分配GPU问题

    使用tensorflow,如果不加设置,即使是很小的模型也会占用整块GPU,造成资源浪费. 所以我们需要设置,使程序按需使用GPU. 具体设置方法: gpu_options = tf.GPUOptio ...

  10. Spring bean的bean的三种实例化方式

     Bean 定义 被称作 bean 的对象是构成应用程序的支柱也是由 Spring IoC 容器管理的.bean 是一个被实例化,组装,并通过 Spring IoC 容器所管理的对象.这些 bean ...