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 ...
随机推荐
- NOIP初赛篇——01计算机常识
发展历史 年代划分 代别 年代 逻辑(电子)元件 第一代 1946-1958 电子管 第二代 1959-1964 晶体管 第三代 1965-1970 集成电路 第四代 1971-至今 大规模.超大规模 ...
- Linux基础命令整合
linux基础命令整理 1.系统相关命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours:minu ...
- Docker学习笔记之Dockerfile
Dockerfile的编写格式为<命令><形式参数>,命令不区分大小写,但一般使用大写字母.Docker会依据Dockerfile文件中编写的命令顺序依次执行命令.Docker ...
- git 遇到 fatal: loose object xxxx (stored in .git/objects/cb/xxxx) is corrupt 问题
我的git版本是2.3.x,用下面这个参考链接的方法也可以解决 参考blog
- 【Linux】dd命令进行磁盘备份
运用dd命令,将/dev/sdb磁盘中所有的数据全部备份到/dev/sdc磁盘上,需要的命令如下 dd if=/dev/sdb of=/dev/sdc bs=1024k 说明,if是需要备份的磁盘 ...
- 到底什么是哈希Hash?
有次面试被问到这个问题? 我说是经过运算的一串字符串,这个回答显然是让人不满意,连自己都不满意! 但是又对其很模糊,那么到底什么是Hash呢? 定义 Hash一般翻译为散列,还有音译为哈希,本文我们统 ...
- 【老孟Flutter】如何提高Flutter应用程序的性能
首先 Flutter 是一个非常高性能的框架,因此大多时候不需要开发者做出特殊的处理,只需要避免常见的性能问题即可获得高性能的应用程序. 重建最小化原则 在调用 setState() 方法重建组件时, ...
- Python编程小技巧(一)
在使用Tkinter编写代码的时候,有时候会忘记某个组件的参数是什么或者忘记某个参数怎么拼写的,此时可以通过如下方式查询组件的参数列表,以按钮组件为例: 1 # -*- coding:utf-8 -* ...
- Q-Q图原理详解及Python实现
[导读]在之前的<数据挖掘概念与技术 第2章>的文章中我们介绍了Q-Q图的概念,并且通过调用现成的python函数, 画出了Q-Q图, 验证了Q-Q图的两个主要作用,1. 检验一列数据是否 ...
- 如何在 Blazor WebAssembly中 使用 功能开关
微软Azure 团队开发的 功能管理 (Feature Management) 包 Microsoft.FeatureManagement可用于实现 功能开关,可以通过 功能开关 特性动态的改变应用程 ...