This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is going to invite distinguished alumnus back to visit and take photos.
  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.
 
Input
  The input contains several test cases, terminated by
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.
 
Output
  If divided successfully, please output "YES" in a
line, else output "NO".
 
Sample Input
3
3 0
1 0
1 2 0
 
Sample Output
YES
/*
二分图染色模板题
*/
#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的更多相关文章

  1. HDU-4751 Divide Groups 染色问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题意:有n个人,每个人都认识一些人,要求把他们分成两个集合,使得两个集合中的人都相符两两认识. ...

  2. HDOJ 4751 Divide Groups

    染色判断二分图+补图 比赛的时候题意居然是反的,看了半天样例都看不懂 .... Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  3. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. Divide Groups 二分图的判定

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. 【HDU4751】Divide Groups

    题目大意:给定 N 个点和一些有向边,求是否能够将这个有向图的点分成两个集合,使得同一个集合内的任意两个点都有双向边联通. 题解:反向思考,对于没有双向边的两个点一定不能在同一个集合中.因此,构建一个 ...

  6. hdu 4751 Divide Groups(dfs染色 或 2-sat)

    Problem Description   This year is the 60th anniversary of NJUST, and to make the celebration more c ...

  7. HDU 4751 Divide Groups

    题目链接 比赛时候,建图建错了.大体算法想到了,不过很多细节都没想好. #include <cstdio> #include <cstring> #include <cm ...

  8. HDU 4751 Divide Groups 2013 ACM/ICPC Asia Regional Nanjing Online

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题目大意:判断一堆人能否分成两组,组内人都互相认识. 解题思路:如果两个人不是相互认识,该两人之 ...

  9. Divide Groups(分组)

    题目链接 题目大意是说输入数字n 然后告诉你第i个人都认识谁? 让你把这些人分成两堆,使这每个堆里的人都互相认识. 做法:把不是互相认识的人建立一条边,则构建二分图,两堆的人肯定都互相认识,也就是说, ...

随机推荐

  1. CentOS关闭火狐浏览器Flash过期提示

    关闭旧版插件屏蔽提示 打开 about:config?filter=extensions.blocklist.enabled 右键切换,关闭flash版本过旧被屏蔽的提示. 参考: http://ti ...

  2. 64位CentOS源码编译方式安装wine

    说明:本文仅作本人笔记的之用,仅供参考.可能因不同环境而不同. 1. 从官网下载最新版的wine-1.6.2.tar.gz 2. 安装相关的包(这里是我安装的,可能由于不同系统已经安装的包不同而不一样 ...

  3. XmlReader读取XML

    StringBuilder output = new StringBuilder(); String xmlString = @"<bookstore> <book gen ...

  4. 为什么要用Markdown写东西

    为什么要用Markdown 不用费心去调格式了,比方说题目加粗什么的,删除线什么的,代码也只要四个空格就好了~ 学起来很简单,几乎没什么学习成本,而收益却很大 这几乎快让我我想从cnblog转到简书了 ...

  5. oracle建表并设置ID为自动增长

    CREATE TABLESPACE shopping DATAFILE 'D:\oracle\mypc\oradata\orcl\shopping.dbf' SIZE 20M AUTOEXTEND O ...

  6. Docker入门教程(八)Docker Remote API

    Docker入门教程(八)Docker Remote API [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第八篇,重点介绍了Docker Remote ...

  7. openssl生成https证书 (转)

    1.首先要生成服务器端的私钥(key文件):openssl genrsa -des3 -out server.key 1024运行时会提示输入密码,此密码用于加密key文件去除key文件口令的命令:o ...

  8. IBatis学习

    (1)建立 SqlMap.config文件 <?xml version="1.0" encoding="utf-8" ?> <sqlMapCo ...

  9. sphinx安装记录 转

    [转]sphinx服务器安装及配置详解 安装PHP sphinx扩展 1.架构:ip192.168.0.200 redhat5.4(64位)2.安装   #cd /usr/local/src   #y ...

  10. 9月8日HTML表单元素(form、文本、按钮、选择)

    表单元素 一.form form代表表单,功能:用于申明表单,定义采集数据的范围,也就是<form>和</form>里面包含的数据将被提交到服务器或者电子邮件里.<for ...