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 ;
}
 

最新文章

  1. CADisplayLink 及定时器的使用
  2. Java Web指导方向
  3. ThinkPHP 中M方法和D方法详解----转载
  4. Form_Form Builder国际化多语言开发(案例)
  5. MAVEN ERROR: unable to find valid certification path to requested target 解决办法
  6. AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
  7. ADO.NET DataSet、DataTable、DataRow、DataView的学习
  8. 1724: [Usaco2006 Nov]Fence Repair 切割木板( 贪心 )
  9. linux如何在日志中查找关键字、前几行、结尾几行
  10. Spring Security 入门(1-3-2)Spring Security - http元素 - intercept-url配置
  11. 01_学习java WEB涉及到的相关技术
  12. Python--day08(文件操作)
  13. 网络编程-SOCKET开发之----2. TCP粘包现象产生分析
  14. tensorboard
  15. 使用redis限制ip访问次数
  16. [代码审计]phpshe开源商城后台两处任意文件删除至getshell
  17. Struts标签判断当前用户是否存在
  18. 用NotePad++如何实现大小写转换
  19. API设计风格(RRC、REST、GraphQL、服务端驱动)
  20. 在Linux下使用sprintf代替atoi实现整型转化为char*

热门文章

  1. 基于Flink的视频直播案例(上)
  2. 清北考前刷题day4下午好
  3. 对象的属性类型 和 VUE的数据双向绑定原理
  4. iOS静态库.Framework制作
  5. srand()
  6. js jquery 获取服务器控件的三种方法
  7. 22 C#中的异常处理入门 try catch throw
  8. [ CodeForces 515 D ] Drazil and Tiles
  9. ubuntu下查看服务器的CPU详细情况
  10. 【Python-2.7】删除空格