HDOJ题目4751 Divide Groups(染色法判二分图)
2015-02-03 17:42
375 查看
Divide Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1412 Accepted Submission(s): 498
[align=left]Problem Description[/align]
![](http://acm.hdu.edu.cn/data/images/C479-1004-1.jpg)
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
If divided successfully, please output "YES" in a line, else output "NO".
[align=left]Sample Input[/align]
3 3 0 1 0 1 2 0
[align=left]Sample Output[/align]
YES
[align=left]Source[/align]
2013 ACM/ICPC Asia Regional Nanjing Online
[align=left]Recommend[/align]
liuyiding | We have carefully selected several similar problems for you: 5169 5168 5167 5166 5165
题目大意:把人分成两组,只有相互认识的可以分成一组,问能不能分
ac代码
#include<stdio.h> #include<string.h> int map[110][110],link[110][110],color[110],n; int dfs(int v,int c) { int i; if(!color[v]) color[v]=c; else { if(color[v]==c) return 0; return 1; } for(i=1;i<=n;i++) { if(link[v][i]&&v!=i) if(dfs(i,-c)) return 1; } return 0; } int solve() { int i; memset(color,0,sizeof(color)); for(i=1;i<=n;i++) { if(!color[i]) if(dfs(i,1)) return 0; } return 1; } int main() { //int n; while(scanf("%d",&n)!=EOF) { int i,j; memset(map,0,sizeof(map)); memset(link,0,sizeof(link)); for(i=1;i<=n;i++) { int x; while(scanf("%d",&x)!=EOF,x) { map[i][x]=1; } } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(!map[i][j]||!map[j][i]) link[i][j]=link[j][i]=1; } } if(solve()) printf("YES\n"); else printf("NO\n"); } }
相关文章推荐
- HDU 4751 Divide Groups【二分图染色】
- HDU 4751 — Divide Groups 交叉染色判二分图
- HDU 4751 Divide Groups (判断二分图染色模板)
- hdu 4751 Divide Groups(判完美二分图)
- HDU 4751 Divide Groups (二分图)
- hdu 4751 Divide Groups 染色
- hdu 4751 Divide Groups 二分图
- HDOJ 4751 - Divide Groups 暴力DFS
- HDU 4751 Divide Groups(二分图的判断)
- HDOJ4751 Divide Groups 模拟
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
- hdu 4751 Divide Groups(2013南京网络赛D题,黑白染色)
- HDU 4751 Divide Groups(二分图判断)
- HDU 4751 Divide Groups(判断是否为二分图)
- hdu 4751 Divide Groups(dfs染色 或 2-sat)
- hdu 4751 Divide Groups (二分图判断)
- HDOJ 题目2444 The Accomodation of Students(染色法判二分图,最大匹配)
- HDU 4751 Divide Groups 【判定二分图】
- HDOJ-----4751---Divide Groups二分判断
- HDU-4751 Divide Groups 染色问题