题意:给你n个点 和 m条边 问是否可以分成三个集合 使得任意两个集合之间的任意两个点都有边

思路:对于其中一个集合v1 我们考虑其中的点1 假设点u和1无边 那么我们可以得到 u一定和点1在一个集合 否则将输出-1 所以我们可以暴力把所有的点先尽可能的分类 最后判断是否可行

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 3e5+7;
typedef long long ll;
const ll mod = 1e9+7;
using namespace std;
int u[N],v[N];
int col[N];
map<int,int> mm[N];
set<int> s[4];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,m; cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>u[i]>>v[i];
mm[u[i]][v[i]]=1;
mm[v[i]][u[i]]=1;
} int tot=0;
for(int i=1;i<=n;i++){
if(!col[i]){
tot++;
col[i]=tot;
if(tot>3){
cout<<"-1"<<endl;
return 0;
}
s[tot].insert(i);
for(int j=i+1;j<=n;j++){
if(mm[i].count(j)) continue;
if(col[j]) continue;
col[j]=tot;
s[tot].insert(j);
}
}
}
if(tot!=3){
cout<<"-1"<<endl;
return 0;
}
for(int i=1;i<=m;i++){
if(col[u[i]]==col[v[i]]){
cout<<"-1"<<endl;
return 0;
}
}
ll a,b,c; a=s[1].size(); b=s[2].size(); c=s[3].size();
if(a*b+b*c+a*c!=m){
cout<<"-1"<<endl;
return 0;
}
for(int i=1;i<=n;i++)
cout<<col[i]<<" ";
cout<<endl;
return 0;
}

Codeforces Round #589 (Div. 2) D. Complete Tripartite(模拟)的更多相关文章

  1. Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)

    链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...

  2. Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  3. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  4. Codeforces Round #589 (Div. 2)

    目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...

  5. Codeforces Round #589 (Div. 2) (e、f没写)

    https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...

  6. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  8. 【Codeforces Round #589 (Div. 2) D】Complete Tripartite

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实这道题感觉有点狗. 思路大概是这样 先让所有的点都在1集合中. 然后随便选一个点x,访问它的出度y 显然tag[y]=2 因为和他相连了嘛 ...

  9. Codeforces Round 589 (Div. 2) 题解

    Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...

随机推荐

  1. Linux命令整理,用户管理,用户组管理,系统管理,目录管理常用命令

    知识点梳理 Linux课堂笔记 学习目标 能够知道什么是Linux系统以及它的应用场景 能够独立完成安装VMware虚拟机和网络配置 能够独立完成安装CentOS以及远程终端SecureCRT 能够熟 ...

  2. zabbix 监控tomcat

    zabbix 监控tomcat server端rpm -ivh jdk-8u20-linux-x64.rpmvi /etc/profileJAVA_HOME=/usr/java/jdk1.8.0_20 ...

  3. innnodb_doublewrite

    有写场景下,双写缓冲确实没必要,例如,你也许像在备库上禁用双写缓冲,此外,一些文件系统,例如zfs做了同样的事,所以,没必要再让innodb做一遍. innodb_double_write=0 即可关 ...

  4. postgresql中权限介绍

    postgresql权限分为实例的权限,数据库的权限,模式的权限,对象的权限,表空间的权限 实例的权限:由pg_hba.conf文件控制,控制那些用户那些IP以哪种方式连接数据库 数据库的权限:是否允 ...

  5. SQL Server management studio使用sa连接时报错与伺服器的连接已成功,但在登入程序是发生错误

    使用Sql Server management studio的sa用户连接数据库时,报如下错误 解决方法: 1.使用windows验证登录 2.右键点击连接,点击属性,点击安全性,选择混合验证 3.重 ...

  6. 微信登录4-开发回调URL

    一.准备 1.引入pom依赖 在要使用HttpClient的项目中加入依赖 <!--httpclient--> <dependency> <groupId>org. ...

  7. 前端知识(二)05-Eslint语法规范检查-谷粒学院

    目录 一.ESLint简介 二.启用ESLint 1.ESLint插件安装 2.插件的扩展设置 3.确认开启语法检查 三.ESLint规则说明 1.规则说明 2.语法规则 一.ESLint简介 ESL ...

  8. scrapy异步的爬虫框架简单的使用

    scrapy异步的爬虫框架 异步的爬虫框架 高性能的数据解析,持久化存储,全栈数据的爬取,中间件,分布式 框架:就是一个集成好了各种功能且具有很强通用性的一个项目模板. 环境安装: Linux: pi ...

  9. std::async的使用总结

    C++98标准中并没有线程库的存在,直到C++11中才终于提供了多线程的标准库,提供了管理线程.保护共享数据.线程间同步操作.原子操作等类.多线程库对应的头文件是#include <thread ...

  10. AES 密钥与 RSA 密钥的关系

    AES 加密说明 - 支付宝开放平台 https://opendocs.alipay.com/open/common/104567 AES 密钥是对接口请求和响应内容进行加密,密文无法被第三方识别,从 ...