Divide Groups

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1835    Accepted Submission(s): 657

Problem Description

  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 <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
const int Max=;
int G[Max][Max];
int path[Max][Max],book[Max],color[Max],book1[Max];
int n;
bool dfs(int u,int co)
{
// cout<<u<<" "<<color[u]<<" "<<co<<endl;
if(color[u]!=-&&color[u]!=co) return true;
if(color[u]==co) return false;
color[u]=!co;
for(int i=;i<=n;i++)
{
if(u==i) continue;
if(path[u][i]||path[i][u])
if(book[i]) if(!dfs(i,!co)) return false;
}
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(book,,sizeof(book));
memset(book1,-,sizeof(book1));
memset(G,,sizeof(G));
memset(path,,sizeof(path));
memset(color,-,sizeof(color));
int tmp;
for(int i=;i<=n;i++)
{
while(scanf("%d",&tmp))
{
if(tmp==) break;
G[i][tmp]=;
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(G[i][j]!=||G[j][i]!=)
{
if(i==j) continue;
book[i]=book[j]=;
path[i][j]=;
}
}
}
int flag=;
for(int i=;i<=n;i++)
{
if(book[i])
if(!dfs(i,)) {flag=;break;}
memset(color,-,sizeof(color));
}
if(flag) printf("NO\n");
else printf("YES\n");
}
return ;
}
 

Divide Groups 二分图的判定的更多相关文章

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

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

  2. HDOJ 4751 Divide Groups

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

  3. 二分图的判定hihocoder1121 and hdu3478

    这两个题目都是二分图的判定,用dfs染色比较容易写. 算法流程: 选取一个没有染色的点,然后将这个点染色,那么跟他相连的所有点一定是不同颜色的,所以,如果存在已经染过颜色的,如果和这个颜色相同的话,就 ...

  4. hdu_2444The Accomodation of Students(二分图的判定和计算)

    hdu_2444The Accomodation of Students(二分图的判定和计算) 标签:二分图匹配 题目链接 题意: 问学生是否能分成两部分,每一部分的人都不相认识,如果能分成的话,两两 ...

  5. 【HDU4751】Divide Groups

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

  6. POJ:2492-Bug's Life(二分图的判定)

    Bug's Life Time Limit: 10000MS Memory Limit: 65536K Description Background Professor Hopper is resea ...

  7. 双栈排序(洛谷P1155)二分图的判定+思维贪心

    题目:戳这里 题目大意: 给你一个数列,问能否通过两个栈的push与pop把它输出成一个升序序列(每个数只能入队并出队一次) 不能的话输出0,能的话输出操作方法 主要思路: 1.判断是否可以成功输出升 ...

  8. Divide Groups(分组)(二分图染色)

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

  9. hdu4751 Divide Groups

    This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is goi ...

随机推荐

  1. c++ class does not name a type (转载)

    转载:http://blog.csdn.net/typename/article/details/7173550 declare class does not name a type 出现这个编译错误 ...

  2. bzoj 2878: [Noi2012]迷失游乐园【树上期望dp+基环树】

    参考:https://blog.csdn.net/shiyukun1998/article/details/44684947 先看对于树的情况 设d[u]为点u向儿子走的期望长度和,du[u]为u点的 ...

  3. 乐搏讲自动化测试-Python语言常识及前景(3)

    相信小伙伴们都知道,随着软件测试行业的发展和进步自动化测试已经成为必然.在竞争日益激烈的市场环境中也是你升职加薪的利器. 所以,小编决定从今天起!将要系统.连续.高质量的持续更新「整套自动化测试」文章 ...

  4. 对mysql修改库里面所有的引擎mysaim 为 innodb

    1.查看当前数据引擎的命令: show engines; 2. USE `[DBNAME]`; SELECT GROUP_CONCAT(CONCAT( 'ALTER TABLE ' ,TABLE_NA ...

  5. 【js】JavaScript parser实现浅析

    最近笔者的团队迁移了webpack2,在迁移过程中,笔者发现webpack2中有相当多的兼容代码,虽然外界有很多声音一直在质疑作者为什么要破坏性更新,其实大家也都知道webpack1那种过于“灵活”的 ...

  6. ACM_校庆素数

    校庆素数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 广财建校33年了,如今迎来了她的校庆. 小财最近想在研究素数,她突发奇想 ...

  7. WCF 相关配置

    WCF错误:413 Request Entity Too Large 在我们用WCF传输数据的时候,如果启用默认配置,传输的数据量过大,经常会出这个错误. WCF包含服务端与客户端,所以这个错误可能出 ...

  8. 小白的python之路 序

    计算机专科毕业,.net开发已有8年有余,中途断断续续,似懂非懂,积累了一些经验知识,但是不求甚解,属于那种一瓶不满半瓶子晃荡,这么一个状态. 主要从事web开发,涉及一些前端jq等,还有接口开发,搜 ...

  9. C#知识点-GDI绘图

    一.开发环境 编译器:VS2013 .Net版本:4.5 二.开发过程 1.画一条直线 private void btnDrawLine_Click(object sender, EventArgs ...

  10. Quartz.Net学习笔记(1)-完整的例子

    一.开发环境 系统:Win10 编译器:VS2013 .Net版本:4.5 Quartz版本:2.3.3 二.涉及程序集 Common.Logging.Core.dll Common.Logging. ...