hdu4751 Divide Groups
After carefully planning, Tom200 announced his activity plan, one
that contains two characters:
1. Whether the effect of the event are good
or bad has nothing to do with the number of people join in.
2. The more
people joining in one activity know each other, the more interesting the
activity will be. Therefore, the best state is that, everyone knows each
other.
The event appeals to a great number of alumnus, and Tom200 finds
that they may not know each other or may just unilaterally recognize others. To
improve the activities effects, Tom200 has to divide all those who signed up
into groups to take part in the activity at different time. As we know, one's
energy is limited, and Tom200 can hold activity twice. Tom200 already knows the
relationship of each two person, but he cannot divide them because the number is
too large.
Now Tom200 turns to you for help. Given the information, can you
tell if it is possible to complete the dividing mission to make the two activity
in best state.
EOF.
Each case starts with a positive integer n (2<=n<=100), which
means the number of people joining in the event.
N lines follow. The i-th
line contains some integers which are the id
of students that the i-th
student knows, terminated by 0. And the id starts from 1.
line, else output "NO".
3 0
1 0
1 2 0
/*
二分图染色模板题
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn = ;
int n,col[maxn];
bool kw[maxn][maxn];
vector<int> g[maxn];
bool dfs(int x,int c){
col[x] = c;
int to;
for(int i = ;i < g[x].size();i++){
to = g[x][i];
if(col[to] == c) return false;
if(!col[to] && !dfs(to,-c)) return false;
}
return true;
}
void get_ans(){
for(int i = ;i <= n;i++){
if(!col[i]){
if(!dfs(i,)){
printf("NO\n");
return;
}
}
}
printf("YES\n");
}
int main(){
int to;
while(scanf("%d",&n) == ){
for(int i = ;i <= n;i++) g[i].clear();
memset(col,,sizeof(col));
memset(kw,,sizeof(kw));
for(int i = ;i <= n;i++){
while(scanf("%d",&to) == &&to){
kw[i][to] = true;
}
}
for(int i = ;i <= n;i++){
for(int j = i + ;j <= n;j++){
if(!kw[i][j] || !kw[j][i]){
g[i].push_back(j);
g[j].push_back(i);
}
}
}
get_ans();
}
return ;
}
hdu4751 Divide Groups的更多相关文章
- HDU-4751 Divide Groups 染色问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题意:有n个人,每个人都认识一些人,要求把他们分成两个集合,使得两个集合中的人都相符两两认识. ...
- HDOJ 4751 Divide Groups
染色判断二分图+补图 比赛的时候题意居然是反的,看了半天样例都看不懂 .... Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- Divide Groups 二分图的判定
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 【HDU4751】Divide Groups
题目大意:给定 N 个点和一些有向边,求是否能够将这个有向图的点分成两个集合,使得同一个集合内的任意两个点都有双向边联通. 题解:反向思考,对于没有双向边的两个点一定不能在同一个集合中.因此,构建一个 ...
- hdu 4751 Divide Groups(dfs染色 或 2-sat)
Problem Description This year is the 60th anniversary of NJUST, and to make the celebration more c ...
- HDU 4751 Divide Groups
题目链接 比赛时候,建图建错了.大体算法想到了,不过很多细节都没想好. #include <cstdio> #include <cstring> #include <cm ...
- HDU 4751 Divide Groups 2013 ACM/ICPC Asia Regional Nanjing Online
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题目大意:判断一堆人能否分成两组,组内人都互相认识. 解题思路:如果两个人不是相互认识,该两人之 ...
- Divide Groups(分组)
题目链接 题目大意是说输入数字n 然后告诉你第i个人都认识谁? 让你把这些人分成两堆,使这每个堆里的人都互相认识. 做法:把不是互相认识的人建立一条边,则构建二分图,两堆的人肯定都互相认识,也就是说, ...
随机推荐
- StringBuilder类与String类的区别
String对象是不可改变的,每次使用String类中的方法时,都要在内存中创建一个新的字符串对象,这就需要为该新对象分配新的空间.在需要对字符串执行重复修改的情况下,与创建新的String对象相关的 ...
- CentOS同步时间
用date查看系统当前时间,date -R 可查看时区. CentOS 同步时间由ntp服务提供,可以用"yum install ntp -y"安装. 装完后运行命令 ntpdat ...
- HDU 5925 Coconuts
2016 CCPC 东北四省赛 D. 一道好题. 现场写崩了. 赛后LSh跟我讲了一种离散化的做法, 没听懂. 题意 一个\(R \cdot C\ (R, C\le 10^9)\) 的矩形点阵上有 $ ...
- 【转载】MFC键盘响应
转载自:传送门 一:首先介绍键盘消息 系统消息: ALT,F1,--F24等,是由系统内部处理的,程序本身就存在,比如F1是帮助键. WM_SYSKEYDOWN WM_SYSKEYUP WM_SYSC ...
- [JavaEE]Get请求URI中带的中文参数在服务端乱码问题的解决方法
在Get请求中,如果请求参数中带有中文,如 http://localhost:8080/DinnerParty/shop/search?query=多伦多, 在服务端拿到的是乱码. 这是因为客户端提交 ...
- JSContext
An instance of JSContext represents a JavaScript execution environment. All JavaScript execution tak ...
- 查看apt-get安装软件的版本
apt-cache search name 查询 apt-get install name 安装 dpkg dpkg dpkg-checkbuilddeps dpkg-genchanges dpkg- ...
- git的基本操作
今天给同事培训了一下git的使用流程,简单记录一下 1,基本概念, 远程库和本地库. 2, git clone git://url/*.git clone远程的代码库到本地 3. 创建本地分支 当前是 ...
- JavaWeb学习笔记——jsp:setproperty和getproperty
- 《CSS3实战》读书笔记 第4章:样式继承
节省你的时间--样式继承 ### 什么是继承? 后代元素可以继承先代元素的一些属性.有了它,可以省去分别定义样式的时间.继承了方向是由外而内的. ### 继承的局限性 应该注意到,有些属性是不适宜继承 ...