HDOJ-----4751---Divide Groups二分判断
来源:互联网 发布:炫光制作软件 编辑:程序博客网 时间:2024/05/16 13:40
Divide GroupsTime Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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.
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
存在两两互相认识关系的人,无论加入哪一边都没有影响,而两两单向认识或者不认识的检查是否满足二分图,进行染色
原来是个模板题,二分图染色模板。
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<map>#include<queue>#include<algorithm>#include<cmath>#include<vector>#define PI acos(-1.0)#define INF 0x3f3f3f3f#define CL(a, b) memset(a, b, sizeof(a))using namespace std;typedef long long LL;const int maxn = 2e2+10;const int MOD = 1e9+7;int link[maxn];bool mp[maxn][maxn];vector <int > G[maxn];bool judge(int u, int color){ link[u] = color; for(int i = 0; i < G[u].size(); i++){ int v = G[u][i]; if(link[v] == color || (link[v] == -1 && !judge(v, !color))) return false; } return true;}int main(){ int a, t, n, kcase = 1; while(scanf("%d", &t) == 1){ for(int i = 1; i <= t; i++) G[i].clear(); CL(mp, false); for(int i = 1; i <= t; i++){ while(scanf("%d", &a) == 1 && a) mp[i][a] = true; } for(int i = 1; i <= t; i++){ for(int j = i+1; j <= t; j++){ if(!mp[i][j] || !mp[j][i]){ G[i].push_back(j); G[j].push_back(i);//两两不互相认识的建边 } } } bool flag = true; CL(link, -1); for(int i = 1; i <= t; i++){ if(link[i] == -1 && !judge(i, 0)){ flag = false; break; } } printf(flag ? "YES\n" : "NO\n"); } return 0;}
0 0
- HDOJ-----4751---Divide Groups二分判断
- hdu 4751 Divide Groups (二分图判断)
- HDU 4751 Divide Groups 二分图判断
- HDU 4751 Divide Groups(二分图判断)
- HDOJ 4751 Divide Groups
- HDU 4751 Divide Groups(二分图的判断)
- HDU 4751 Divide Groups(判断是否为二分图)
- HDU 4751 Divide Groups (判断二分图染色模板)
- HDU 4751 Divide Groups(判断二分图)
- HDOJ 4751 - Divide Groups 暴力DFS
- HDOJ题目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
- HDU-4751-Divide Groups
- 计蒜客 青云的机房组网方案
- Qt 进度条填充效果
- 深刻理解 抽象类与接口之间的区别
- 【leetcode】5. Longest Palindromic Substring
- 常用DIV操作兼论JQuery语法
- HDOJ-----4751---Divide Groups二分判断
- 德赛西威2311a汽车导航仪不能更新屏保时间的解决方案
- DNS解释问题:java.net.UnknownHostException
- Android中其他常见的安全问题
- 利用SQL Server 2008完成对基本表的操作 第三章(一)
- php 连接 SQL Server 2008
- 弹框问题
- Android Studio调背景颜色
- UVA 11809