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 ...
随机推荐
- Linux Mint 19.1 安装 Docker 过程笔记
Linux Mint 19.1 安装 Docker 过程笔记 参考了很多教程,可能有很多教程已经过时. 综合记录一下. 首先修改一下系统的源,使用国内的源. 然后安装 docker sudo apt ...
- Python数据集变量及相关含义
- Java练习 SDUT-1255_小明A+B
小明A+B Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 小明今年3岁了, 现在他已经能够认识100以内的非负整数, ...
- 19-1 djanjo中admin的简单用法
1. 创建管理员账号 python3 manage.py createsuperuser 2. 在admin注册我们的表 在app目录下面的admin.py里面按以下语法注册 admin.site.r ...
- mysql 连接慢的问题
现象: 今发现站点訪问数据库变慢,经查,查询数据库非常快,连接数据库比較耗时. 解决的方法: 在mysql的配置文件my.cnf中,在[mysqld]以下加上这个配置就能够了. 附录:[mysqld] ...
- notepad++最有用的快捷键
Ctrl+Tab 实现在多个打开的窗口间切换 Ctrl+Shift+Q 区块注释 Ctrl+K 行注释 Tab 缩进 Shift+Tab 删除缩进 先按住键盘上的“ctrl”键不放,然后滚动鼠标的 ...
- IOS开发之UISearchBar自定义外观
MySearchBar.h如下: @interface MySearchBar : UISearchBar - (void)layoutSubviews; @end MySearchBar.m如下 ...
- @hdu - 6427@ Problem B. Beads
目录 @description@ @solution@ @accepted code@ @details@ @description@ 有 m 种不同颜色的珠子,颜色分别为 1~m,每一种颜色的珠子有 ...
- 2011-04-21 运程连Oracle的方法
oracle无法远程连接重要原因,即使防火墙开放1521端口, 但是返回包可能是随机端口,所以仍有可能被防火墙阻止. 解决方法: 在注册表中增加一个字符串值如下.可解决 花费两天找到的方法 [HKEY ...
- H3C 分组交换连接模型