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 ...
随机推荐
- java代码简单实现栈
1. 基于数组简单实现 /** * @author <a herf="mailto:yanwu0527@163.com">XuBaofeng</a> * @ ...
- iOS 9 适配系列教程
http://www.cocoachina.com/ios/20150703/12392.html 本文是投稿文章,作者:ChenYilong(https://github.com/ChenYilon ...
- 如何解决iOS内存错误
由于iOS5.0之前没有自动应用计数机制,也没有Java那样的垃圾回收功能.我们都需要自己管理和控制对象的回收,这是一件很麻烦的事情,也是做iOS项目中最容易出现的问题.如果不掌握这些方法,调试这些问 ...
- Python语言的特点
- Android 高仿微信(QQ)滑动弹出编辑、删除菜单效果,增加下拉刷新功能
不可否认,微信.QQ列表的滑动删除.编辑功能着实很经典(从IOS那边模仿过来的),然.Android这边,对列表的操作,其实大多还停留上下文菜单来实现. Android如何实现list item的滑动 ...
- python如何自动发送邮件
#coding=utf-8 import smtplib from email.mime.text import MIMEText from email.mime.application import ...
- E - D Tree HDU - 4812 点分治+逆元
这道题非常巧妙!!! 我们进行点分治的时候,算出当前子节点的所有子树中的节点,到当前节点节点的儿子节点的距离,如下图意思就是 当前节点的红色节点,我们要求出红色节点的儿子节点绿色节点,所有绿色的子树节 ...
- oracle函数 floor(x)
[功能]返回小于等于x的最大整数值 [参数]x,数字型表达式 [返回]数字 [示例] select floor(3.1),floor(2.8+1.3),floor(0) from dual; 返回4, ...
- js判断浏览设备是 手机端,电脑端还是平板端
console.log(navigator.userAgent); var os = function() { var ua = navigator.userAgent, isWindowsPhone ...
- Android Animation动画详解(二): 组合动画特效
前言 上一篇博客Android Animation动画详解(一): 补间动画 我已经为大家介绍了Android补间动画的四种形式,相信读过该博客的兄弟们一起都了解了.如果你还不了解,那点链接过去研读一 ...