题意:给你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. 两个很赞的用法(count函数里的表达式+计算时间间隔)

    1.count函数里写表达式 #无效写法,这样写不会判断表达式(ischecked=0),会全部列出来 SELECT cardid FROM search_detail GROUP BY cardid ...

  2. Dubbo 就是靠它崭露头角!(身为开源框架很重要的一点)

    Hola,我是 yes. 经过了 RPC 核心和 Dubbo 微内核两篇文章后,今天终于要稍稍深入一波 Dubbo 了. 作为一个通用的 RPC 框架,性能是很重要的一环,而易用性和扩展性也极为重要. ...

  3. 使用Java语言编写一个五子棋UI界面并实现网络对战功能(非局域网)

    使用Java语言编写一个五子棋UI界面并实现网络对战功能(非局域网) 一,前期准备 1,Java IDE(Eclipse)与JDK的安装与配置jdk-15.0.1-免配置路径版提取码:earu免安装版 ...

  4. 【Azure Developer】使用Postman获取Azure AD中注册应用程序的授权Token,及为Azure REST API设置Authorization

    Azure Active Directory (Azure AD) is Microsoft's cloud-based identity and access management service, ...

  5. 使用nodejs和express搭建http web服务

    目录 简介 使用nodejs搭建HTTP web服务 请求nodejs服务 第三方lib请求post 获取http请求的正文 Express和使用express搭建http web服务 express ...

  6. Redis Cluster 集群节点信息 维护篇(二)

    集群信息文件: # cluster 集群内部信息对应文件,由集群自动维护. /data/soft/redis/6379data/nodes-6379.conf 集群信息查看: ./redis-trib ...

  7. L(kali)A(apache)M(mysql)P(php)环境+wordpress站点搭建

    一:LAMP环境配置 首先LAMP(linux+apache+mysql+php)即为本次搭建网站所需的环境,由于本次使用的debian衍生版kali版本自带lamp,因此只要在服务器上启动相应服务既 ...

  8. SAP 修改数据元素 注意事项

    在修改数据元素的时候,通常要注意一下几点: 1.在修改完数据元素后,如果激活不成功,那么就要通过SE14进入数据库实用程序,在对象名处输入数据元素相关联的表的名称 下面词典对象选择表,然后点击编辑,处 ...

  9. 容器编排系统K8s之包管理器helm基础使用(二)

    前文我们介绍了helm的相关术语和使用helm安装和卸载应用,回顾请参考:https://www.cnblogs.com/qiuhom-1874/p/14305902.html:今天我们来介绍下自定义 ...

  10. [Usaco2007 Feb]Cow Party

    题目描述 农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前 ...