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个人都认识谁? 让你把这些人分成两堆,使这每个堆里的人都互相认识. 做法:把不是互相认识的人建立一条边,则构建二分图,两堆的人肯定都互相认识,也就是说, ...
随机推荐
- 数据结构1 线段树查询一个区间的O(log N) 复杂度的证明
线段树属于二叉树, 其核心特征就是支持区间加法,这样就可以把任意待查询的区间$[L, R]$分解到线段树的节点上去,再把这些节点的信息合并起来从而得到区间$[L,R]$的信息. 下面证明在线段树上查询 ...
- Linux下安装webstorm
Linux下安装webstorm 1--在webstorm官网里面下载最新的版本 WebStorm-11.0.3.tar.gz 2--创建webstorm的安装目录 #mkdir /usr/webst ...
- iOS - 沙盒规范
1.模拟器沙盒目录文件都在个人用户名文件夹下的一个隐藏文件夹里,中文叫资源库,他的目录其实是Library. 因为应用是在沙箱(sandbox)中的,在文件读写权限上受到限制,只能在几个目录下读写文件 ...
- python03 面向对象的编程01
话不多说,直接进入正文: 编程思想: 我个人所了解的有2种,还有个函数式编程的概念模模糊糊(大概是把常用的代码封装成一个函数,重复调用即可,先认为就是这样吧) 1 面向对象:面向对象是把所有的事务物当 ...
- django_restframework_angularjs
用Django Rest Framework和AngularJS开始你的项目 作者:Kevin Stone原帖:Getting Started with Django Rest Framework a ...
- php发送http请求方法实例及详解
http请求有get,post. php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]. file_get_contents();详情见:http://www.whosmall.com ...
- mybatis 传递参数的方法总结
有三种mybatis传递参数的方式: 第一种 mybatis传入参数是有序号的,可以直接用序号取得参数 User selectUser(String name,String area); 可以在xml ...
- 【转】jquery的extend和fn.extend
jQuery为开发插件提拱了两个方法,分别是: jQuery.fn.extend(object); jQuery.extend(object); jQuery.extend(object); 为扩展j ...
- properties 配置文件中值换行的问题
在使用properties配置文件的时候我们经常碰到如下两个问题 1:当a=b中的b值内容特别长的时候为了阅读方便我们手动换行,但如果我们直接回车那么后面的数据就会丢失.那如何解决呢? 例如: a=a ...
- python操作数据库
一,安装mysql 如果是windows 用户,mysql 的安装非常简单,直接下载安装文件,双击安装文件一步一步进行操作即可. Linux 下的安装可能会更加简单,除了下载安装包进行安装外,一般的l ...