hdu4751 Divide Groups
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.
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.
line, else output "NO".
3 0
1 0
1 2 0
/*
二分图染色模板题
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn = ;
int n,col[maxn];
bool kw[maxn][maxn];
vector<int> g[maxn];
bool dfs(int x,int c){
col[x] = c;
int to;
for(int i = ;i < g[x].size();i++){
to = g[x][i];
if(col[to] == c) return false;
if(!col[to] && !dfs(to,-c)) return false;
}
return true;
}
void get_ans(){
for(int i = ;i <= n;i++){
if(!col[i]){
if(!dfs(i,)){
printf("NO\n");
return;
}
}
}
printf("YES\n");
}
int main(){
int to;
while(scanf("%d",&n) == ){
for(int i = ;i <= n;i++) g[i].clear();
memset(col,,sizeof(col));
memset(kw,,sizeof(kw));
for(int i = ;i <= n;i++){
while(scanf("%d",&to) == &&to){
kw[i][to] = true;
}
}
for(int i = ;i <= n;i++){
for(int j = i + ;j <= n;j++){
if(!kw[i][j] || !kw[j][i]){
g[i].push_back(j);
g[j].push_back(i);
}
}
}
get_ans();
}
return ;
}
hdu4751 Divide Groups的更多相关文章
- HDU-4751 Divide Groups 染色问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题意:有n个人,每个人都认识一些人,要求把他们分成两个集合,使得两个集合中的人都相符两两认识. ...
- HDOJ 4751 Divide Groups
染色判断二分图+补图 比赛的时候题意居然是反的,看了半天样例都看不懂 .... Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- Divide Groups 二分图的判定
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 【HDU4751】Divide Groups
题目大意:给定 N 个点和一些有向边,求是否能够将这个有向图的点分成两个集合,使得同一个集合内的任意两个点都有双向边联通. 题解:反向思考,对于没有双向边的两个点一定不能在同一个集合中.因此,构建一个 ...
- hdu 4751 Divide Groups(dfs染色 或 2-sat)
Problem Description This year is the 60th anniversary of NJUST, and to make the celebration more c ...
- HDU 4751 Divide Groups
题目链接 比赛时候,建图建错了.大体算法想到了,不过很多细节都没想好. #include <cstdio> #include <cstring> #include <cm ...
- HDU 4751 Divide Groups 2013 ACM/ICPC Asia Regional Nanjing Online
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题目大意:判断一堆人能否分成两组,组内人都互相认识. 解题思路:如果两个人不是相互认识,该两人之 ...
- Divide Groups(分组)
题目链接 题目大意是说输入数字n 然后告诉你第i个人都认识谁? 让你把这些人分成两堆,使这每个堆里的人都互相认识. 做法:把不是互相认识的人建立一条边,则构建二分图,两堆的人肯定都互相认识,也就是说, ...
随机推荐
- Android——PULL解析XML
简介 Android中常常使用XML文件保存用户的APP设置信息.因此需要对XML文件的相关操作进行了解.本文将以<学生信息管理系统>为案例背景进行介绍相关的XML解析的介绍,以及其他相关 ...
- C#用正则表达式对IP进行排序
static void Main(string[] args) { string IPs = " 192.168.1.1 202.47.4.6 1.2.3.3 "; Console ...
- Logistic Regression分类器
1. 两类Logistic回归 Logistic回归是一种非常高效的分类器.它不仅可以预测样本的类别,还可以计算出分类的概率信息. 不妨设有$n$个训练样本$\{x_1, ..., x_n\}$,$x ...
- 北京地铁站点遍历最少经站次数问题普遍意义上是一个NP问题,目前不存在多项式时间算法能够解决该问题
http://www.cnblogs.com/jiel/p/5852591.html 众所周知求一个图的哈密顿回路是一个NPC问题: In the mathematical field of grap ...
- linux 设置mysql 数据库编码utf8
转载地址http://www.linuxidc.com/Linux/2015-08/121676.htm在MySQL数据库中, 当插入数据无法支持中文时, 可将该数据库的编码集设置为utf8, 故在创 ...
- ubuntu14.04设置开机亮度
1 查看自己的系统亮度的最大值: cd /sys/class/backlight 笔记本的显卡型号不同->亮度调节文件夹名会不同. 2 我的是intel_backlight cd intel_b ...
- 【原】gulp快速入门
今天刚入职了一家新公司,结果明天就要开始项目了.上级说要用gulp来打包代码,所以今晚花了一晚来看这个gulp, 可以说已经入门了.所以做一个小小的总结 : 首先全局安装gulp npm instal ...
- Git创建ssh-key
打开git bash界面,输入: ssh-keygen -t rsa -C "yourname@email.com" 一路回车,后续保持默认值即可. 把C:\users\yourn ...
- Distinct
SELECT 指令让我们能够读取表格中一个或数个栏位的所有资料.这将把所有的资料都抓出,无论资料值有无重复.在资料处理中,我们会经常碰到需要找出表格内的不同资料值的情况.换句话说,我们需要知道这个表格 ...
- String类中的一些函数使用方法
最常用的就是Length()函数了,求字符串的长度 String s="";int i=s.length();i结果为0. 如果是String s=null;int i=s.len ...