hdu4751
来源:互联网 发布:java lang包 编辑:程序博客网 时间:2024/06/10 14:39
C - Divide Groups
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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.
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
33 01 01 2 0
Sample Output
YES题意:有个人要开两个party,来的一些人有的之间认识有的之间不认识,要让在一个party里的所有人都相互认识,能不能办得到,可以利用二分图判断解决,不认识的人之间建边,判断二分图:ac代码:#include <iostream>#include <stdio.h>#include <vector>#include <string.h>#include <queue>using namespace std;const int maxn=1000;vector<int>G[maxn];int col[maxn];bool bfs(int s){ col[s]=1; queue<int>que; que.push(s); while(!que.empty()) { int u=que.front(); que.pop(); for(int i=0; i<G[u].size(); i++) { int v=G[u][i]; if(col[v]==-1) { que.push(v); col[v]=!col[u]; } if(col[v]==col[u]) return false; } } return true;}int map[maxn][maxn];int main(){ int n; while(~scanf("%d",&n)) { memset(map,0,sizeof(map)); for(int i=1; i<=n; i++) { int x; scanf("%d",&x); while(x!=0) { map[i][x]=1; scanf("%d",&x); }; } for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(map[i][j]==0||map[j][i]==0) { G[i].push_back(j); G[j].push_back(i); } } } memset(col,-1,sizeof(col)); for(int i=1;i<=n;i++) { if(col[i]==-1&&!bfs(i)) { printf("NO\n"); goto endW; } } puts("YES"); endW:; for(int i=1;i<=n;i++) G[i].clear(); } return 0;}
0 0
- hdu4751
- hdu4751(BFS)
- hdu4751 two-sat
- HDU4751 Divide Groups---bfs
- HDU4751 Divide Groups
- hdu4751(二分图判定)
- HDU4751 二分图判断
- hdu4751(判断二分图)
- hdu4751 二分图的判断
- hdu4751 最短路+背包dp
- hdu4751(判断二分图)
- hdu4751 Divide Groups (二分图判定)
- HDU4751 -(广义孪生素数猜想)
- Get与Post的区别
- 蓝桥杯 连号区间数
- iOS - UIScrollView 显示出来后 偏移64的问题
- ubuntu 下如何在eclipse上安装部署发布tomcat
- Git基础
- hdu4751
- Android传感器的应用
- 在Windows环境下搭建Nginx文件服务器(简单实用版)
- 可变参数宏__VA_ARGS__
- 欢迎使用CSDN-markdown编辑器
- 【排序】直接插入排序
- C++中头文件相互包含与前置声明
- Android 数据查询query函数参数解析
- 工作问题-java-利用jsonResult判断返回ajax问题