乍一看,嗯,图论题,不错;

结果,这尼玛是模拟????

传送链接: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的更多相关文章

  1. CodeForces - 1228D (暴力+思维+乱搞)

    题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条 ...

  2. Codeforces 1228D. Complete Tripartite

    传送门 不妨设 $1$ 号点在集合 $1$ 里 那么对于其他点,有且只有所有和 $1$ 没有边的点都在集合 $1$ 里 考虑不在集合 $1$ 的任意一个点 $x$ ,不妨设它在集合 $2$ 里 那么所 ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Spring读取mybatis在多个jar包下的的mapper文件

     刚开始的时候我的配置文件在同名目录下都是在/mapper下,导致只能读取一个jar中的mapper文件.先解决如下: 1.将mapper文件放在不能放在同名的目录下.        比如:user. ...

  2. oracle函数 LENGTHC(c1).LENGTH2(c1).LENGTH4(c1)

    [功能]返回字符串的长度; [说明]多字节符(汉字.全角符等),按1个字符计算 [参数]C1 字符串 [返回]数值型 [示例] SQL> select length('高乾竞'),length( ...

  3. laravel5.4 前后台未登陆,跳转到各自的页面

    https://www.imooc.com/wenda/detail/378208?t=266634 laravel我做了前后台登陆,后台未登录跳转到前台登陆页面了. 我想让后台未登入跳转到后台登陆页 ...

  4. SCSS语法格式及编译调试

    一.SASS编译 Sass 的编译有多种方法: 命令编译 GUI工具编译 自动化编译 1.1 命令编译 1)单文件编译 sass <要编译的Sass文件路径>/style.scss:< ...

  5. jieba分词流程及部分源码解读(一)

    首先我们来看一下jieba分词的流程图: 结巴中文分词简介 1)支持三种分词模式: 精确模式:将句子最精确的分开,适合文本分析 全模式:句子中所有可以成词的词语都扫描出来,速度快,不能解决歧义 搜索引 ...

  6. HTML静态网页--图片热点

  7. 洛谷P1310 表达式的值 题解 栈/后缀表达式的应用

    题目链接:https://www.luogu.org/problem/P1310 本题涉及算法:栈.前缀表达式转后缀表达式,动态规划思想. 这道题目我思考了好长时间,第一时间让我做的话我也做不出来. ...

  8. Codeforces Round #177 (Div. 1 + Div. 2)

    A. Polo the Penguin and Segments 模拟. B. Polo the Penguin and Matrix 每个数字模d余数必须一样. 枚举结果,可计算操作次数,取最小. ...

  9. Python--day40--threading模块的几个方法

    import time import threading #threading.get_ident() 查看当前进程号 def wahaha(n): time.sleep(0.5) print(n,t ...

  10. Python--day40线程理论

    1,进程: