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

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

传送链接: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. [牛腩]如何关闭.net framework4.0的请求验证 标签: 发布 2015-07-31 09:27 887人阅读 评论(38)

    敲牛腩的时候,点击运行提示:从客户端中检测到有潜在危险的 Request.Form 值,感觉自己代码敲的并没有问题,于是开始各种查,下面分享一下我对此进行的研究. 为什么会报这个错误? 在 Web 应 ...

  2. 伪元素 before 和 after 各种妙用

    大家可能对伪类和伪元素有点迷糊,在介绍具体用法之前,简单介绍下伪类和伪元素.伪类大家听的多了,伪元素可能听到的不是那么频繁,其实 CSS 对这两个是有区分的. 这里整理总结下: 有时你会发现伪类元素使 ...

  3. Node.js MVC模式+MongoDB实现学员管理系统

    目录结构: 项目入口文件 /* Author:张波 */ /* 文件说明: 此文件是本项目的入口文件 启动这个项目,会先执行本文件中的代码 */ // 1. 引入模块 const http = req ...

  4. Hbase数据模型物理视图

  5. oracle函数 dbtimezone

    [功能]:返回时区 [参数]:没有参数,没有括号 [返回]:字符型 [示例]select dbtimezone from dual;

  6. @loj - 2288@「THUWC 2017」大葱的神力

    目录 @description@ @solution@ @data - 1@ @data - 2@ @data - 3@ @data - 4@ @data - 5@ @data - 6@ @data ...

  7. SaltStack之用户账户管理

    在Salt.state中,user 模块是用来创建用户和管理用户设定的,用户可以被设置成 present 状态或者 absent 状态 注释: present:添加用户 absent   : 删除用户 ...

  8. 测试代码的执行时间魔法方法%time和%timeit

    对于规模更大.运行时间更长的数据分析应用程序,你可能会希望测试一下各个部分或函数调用或语句的执行时间.你可能会希望了解某个复杂计算过程中到底是哪些函数占用的时间最多.幸运的是,在开发和测试代码的过程中 ...

  9. oracle用NOT EXISTS替代NOT IN

    在子查询中,NOT IN子句将执行一个内部的排序和合并. 无论在哪种情况下,NOT IN都是最低效的 (因为它对子查询中的表执行了一个全表遍历).  为了避免使用NOT IN ,我们可以把它改写成外连 ...

  10. oracle 基础表的选择

    基础表(Driving Table)是指被最先访问的表(通常以全表扫描的方式被访问). 根据优化器的不同, SQL语句中基础表的选择是不一样的. 如果你使用的是CBO (COST BASED OPTI ...