CodeForces - 1228D
乍一看,嗯,图论题,不错;
结果,这尼玛是模拟????
传送链接:https://codeforces.com/contest/1228/problem/D
看了大佬的代码瞬间就明白了许多!!!

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define maxn 300300
using namespace std;
int de[maxn];
vector<int>anc[100]; int n, m;
int vis[maxn];
int dfn[maxn];
int flag = 0;
set<pair<int, int>>ins;
int main() {
int be, en;
scanf("%d %d", &n, &m);
if (m == 0) {
printf("-1\n");
return 0;
}
for (int i = 0; i < m; i++) {
scanf("%d %d", &be, &en);
ins.insert({ be,en });
ins.insert({ en,be });
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (dfn[i]) continue; cnt++;
for (int j = i; j<=n ; j++) {
if (ins.find({ i,j }) == ins.end()) {
dfn[j] = cnt;
anc[cnt].push_back(j);
}
}
}
if (cnt != 3 || anc[1].size() * anc[2].size() + anc[2].size() * anc[3].size() + anc[3].size() *anc[1].size() != m) {
printf("-1\n");
return 0;
}
else {
for (int i = 1; i <= 3; i++) {
for (int j = i + 1; j <= 3; j++) {
for (int k = 0; k < anc[i].size(); k++) {
int x = anc[i][k];
for (int s = 0; s < anc[j].size(); s++) {
int p = anc[j][s];
if (ins.find({ x, p }) == ins.end()) {
printf("-1\n");
return 0;
}
}
}
}
}
}
for (int i = 1; i <= n; i++) {
printf("%d ", dfn[i]);
}
printf("\n");
return 0;
}
CodeForces - 1228D的更多相关文章
- CodeForces - 1228D (暴力+思维+乱搞)
题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条 ...
- Codeforces 1228D. Complete Tripartite
传送门 不妨设 $1$ 号点在集合 $1$ 里 那么对于其他点,有且只有所有和 $1$ 没有边的点都在集合 $1$ 里 考虑不在集合 $1$ 的任意一个点 $x$ ,不妨设它在集合 $2$ 里 那么所 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- Maven中央存储库 和 如何从Maven远程存储库下载?
当你建立一个 Maven 的项目,Maven 会检查你的 pom.xml 文件,以确定哪些依赖下载.首先,Maven 将从本地资源库获得 Maven 的本地资源库依赖资源,如果没有找到,然后把它会从默 ...
- ELK之开心小爬爬
1.开心小爬爬 在爬取之前需要先安装requests模块和BeautifulSoup这两个模块 ''' https://www.autohome.com.cn/all/ 爬取图片和链接 写入数据库里边 ...
- HZOI 可怜与超市
网上搜不着,八成又是哪个学长留下的…… 因为考试第二题我们都好不容易才搞懂,学长有给我们扔了几道类似的题. 其实这道题思路挺好想的,就是一些细节还有复杂度比较难弄,好难调啊. 看到题的第一眼以为是树形 ...
- 微信支付、支付宝支付和QQ钱包支付
最近忙于对接微信支付和支付宝支付,注册微信公众号,认证公众号,注册微信支付商户号并进行认证: 签约支付宝支付产品(手机网站支付.PC网站支付),注册支付宝企业账号(企业账号权限更大): 注册QQ钱包商 ...
- hdu 3234 Exclusive-OR (并查集)
Problem - 3234 题意不难理解,就是给出一些断言,以及一些查询,回答查询或者在找到断言矛盾以后沉默不做任何事. 这题其实就是一个并查集的距离存储问题,只要记录并查集元素的相对值以及绝对值就 ...
- 洛谷 1602 Sramoc问题
Description 话说员工们整理好了筷子之后,就准备将快餐送出了,但是一看订单,都傻眼了:订单上没有留电话号码,只写了一个sramoc(k,m)函数,这什么东西?什么意思?于是餐厅找来了资深顾问 ...
- js递归遍历树结构(tree)
如图: 代码: let datas = [] //是一个树结构的数据 setName(datas){ //遍历树 获取id数组 for(var i in datas){ this.expandedKe ...
- 十分钟学会 Fiddler
一.Fiddler介绍 Fiddler是一个http抓包改包工具,fiddle英文中有"欺骗.伪造"之意,与wireshark相比它更轻量级,上手简单,因为只能抓http和http ...
- typescript基础语法--变量/函数/指令/类
博客地址 :https://www.cnblogs.com/sandraryan/ 要把ts文件引入到html中,首先要转码为js文件. 步骤: 终端运行: npm i -g typescript t ...
- [C#] ServiceStack.Redis如何批量的pop数据?
要安全的批量pop数据,有两个办法: 1.用事务(不用事务的话可能导致重复读.ServiceStack的pipeline是没有自带事务的.) 2.执行lua脚本 我这里提供用事务的实现方法: publ ...