Codeforces Round #589 (Div. 2) D. Complete Tripartite(模拟)

题意:给你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(模拟)的更多相关文章
- Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)
链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...
- 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\) ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #589 (Div. 2)
目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...
- Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...
- 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 ...
- 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 ...
- 【Codeforces Round #589 (Div. 2) D】Complete Tripartite
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实这道题感觉有点狗. 思路大概是这样 先让所有的点都在1集合中. 然后随便选一个点x,访问它的出度y 显然tag[y]=2 因为和他相连了嘛 ...
- Codeforces Round 589 (Div. 2) 题解
Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...
随机推荐
- UML软件工程复习——用例图和类图
------------恢复内容开始------------ 软件产品开发流程是需求.分析.设计.实现. 面向对象三大特征:继承性,封装性.多态性 模型将软件生命周期划分为软件计划.需求分析和定义.软 ...
- Docker一秒进阶
tar包: 从tar包导入:docker load < xxxx.tar docker run -d -p 8080:80 --name [名字] -v `pwd`:/usr/share/ngi ...
- js原型链原理
先附上原型链的图,能看懂的本文就没必要看了,看不懂的可以带着疑问看文章 一.构造函数 什么是构造函数:当一个普通函数创建一个类对象是,那么就程它为构造函数. 特点: 默认首字母大写 使用new关键字来 ...
- 【JavaWeb】Servlet 程序
Servlet 程序 Servlet Servlet 是在 Web 服务器中运行的小型 Java 程序.Servlet 通常通过 HTTP(超文本传输协议)接收和响应来自 Web 客户端的请求. ...
- docker迁入迁出mysql
docker迁出mysql数据库 测试环境: docker服务器 mysql服务器 IP 192.168.163.19 192.168.163.16 操作系统 CentOS7.8 CentOS7.8 ...
- python学习笔记 | wordcloud安装指南
问题: 直接在命令行输入: pip install wordcloud 不出意外,直接报错,显示缺失vc*****.bat,意思是缺失vc版本,这个安装方式基本可以扔掉. 解决: http://t.c ...
- leetcode 1593. 拆分字符串使唯一子字符串的数目最大(DFS,剪枝)
题目链接 leetcode 1593. 拆分字符串使唯一子字符串的数目最大 题意: 给你一个字符串 s ,请你拆分该字符串,并返回拆分后唯一子字符串的最大数目. 字符串 s 拆分后可以得到若干 非空子 ...
- Inlook - 你的私人工作助理 V1.0.0.2
Inlook - Your personal assistant 中文版|English version Introduction Inlook是为在桌面上直观地提醒用户收到未读邮件和日程安排而开发的 ...
- [Ceoi2004]Journey
题目描述 给出N个点,及你的出发点K. 接下来N-1行描述有关边的开始点,结束点,边长.保证图中不会有环 接下来给出数字J,代表你要走多少个点. 接下来J个数字,代表你要走过的点的编号.当然你可以自己 ...
- 动态改变div标签中的内容
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...