Codeforces Round #589 (Div. 2)D(思维,构造)
#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(思维,构造)的更多相关文章
- 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\) ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #542(Div. 2) CDE 思维场
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- Codeforces Round #181 (Div. 2) A. Array 构造
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
- 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 ...
随机推荐
- 理解javaBean
1:什么是JavaBean 组件?使用JavaBean 组件有什么优点?答案:现在软件开发都已经转向了基于组件的开发,目前具备代表性的组件技术有微软的COM.COM+,有Sun 的JavaBean 和 ...
- 一段讯飞、百度等语音识别API无法识别的语音最终解决办法
最近在做语音识别.字幕扒词相关的工作,遇到了一段录音(https://download.csdn.net/download/u014220286/12169183,各位有兴趣的可以下载下来试试),音质 ...
- opencv:形态学操作-开闭操作
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- buuctf 基础破解
首先下载压缩包 解压之后发现是另一个压缩包 另一个压缩包上写着基础破解 然后用暴力破解的方法破解 然后搜了一下 暴力破解一般的长度是多少 然后搜到的结果是 长度为8的时候电脑都要破解好几年 所以我猜测 ...
- 吴裕雄 python 机器学习——数据预处理正则化Normalizer模型
from sklearn.preprocessing import Normalizer #数据预处理正则化Normalizer模型 def test_Normalizer(): X=[[1,2,3, ...
- JDBC 基础用法学习
JDBC概述 java 数据库链接,sun公司退出的 java 访问数据库的标准规范接口 是一种用于执行SQL语句的 java API 可以作为多种关系数据库提供统一接口 是一组 java 工具类和接 ...
- springboot集成实现秒杀
springboot集成开发实现商场秒杀 加入主要依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...
- numpy-sum函数
看一个例子就懂了 c = array([[[0, 1, 2, 0, 1, 2]], [[0, 1, 2, 0, 1, 2]]]) print('{0}\n'.format(c.shape)) prin ...
- thinkphp 连接webservice接口
嗯,我现在真的好像骂人啊,但是我又是个文明的人,所以我就写出来让自己冷静一下 ok,正事,thinkphp连别人写的webservice接口 刚开始他叫什么nc接口,就把我给骗了,这就是人家的名字,和 ...
- python中的while
while循环 循环就是一个重复的过程,不断的重复.while循环又称条件循环 while 条件: code 1 code 2 code 3 ... ##实现ATM的输入密码重新输入的功能 while ...