Wrestling Match

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2097    Accepted Submission(s): 756

Problem Description
Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player".
 
Input
Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known "good players" and the number of known "bad players".In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a "good player" number.The last line contains Y different numbers.Each number represents a known "bad player" number.Data guarantees there will not be a player number is a good player and also a bad player.
 
Output
If all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".
 
Sample Input
5 4 0 0
1 3
1 4
3 5
4 5
5 4 1 0
1 3
1 4
3 5
4 5
2
 
Sample Output
NO
YES
 
Source
 
思路:现将已知身份的人染色,之后对每个人根据对应关系进行染色,若出现矛盾,或者有人没被染上(不联通),则输出NO,否则YES。
代码:
 #include<bits/stdc++.h>
//#include<regex>
#define db double
#include<vector>
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define MP make_pair
#define PB push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define fr(i,a,b) for(int i=a;i<=b;i++)
const int N=1e3+;
const int mod=1e9+;
const int MOD=mod-;
const db eps=1e-;
const db PI=acos(-1.0);
using namespace std;
vector<int> g[N];
int n,m,x,y,ok;
int vis[N];
void dfs(int u)
{
int f=;
if(vis[u]==-) vis[u]=,f=;
for(int i=;i<g[u].size();i++){
int v=g[u][i];
if(vis[v]==-) vis[v]=-vis[u],dfs(v);//染色
else if(vis[v]==vis[u]&&f==) f=,vis[u]=-vis[v];//最多变换一次染色方式
else if(vis[v]==vis[u]) ok=;//矛盾
}
}
int main()
{
while(scanf("%d%d%d%d",&n,&m,&x,&y)==)
{
ok=;
for(int i=;i<=n;i++) g[i].clear();
memset(vis,-, sizeof(vis));
while(m--)
{
int u,v;
ci(u),ci(v);
g[u].push_back(v);
g[v].push_back(u);
}
while(x--){
int u;ci(u);vis[u]=;
}
while(y--){
int u;ci(u);vis[u]=;
}
for(int i=;i<=n;i++){
if(g[i].size()) dfs(i);
}
for(int i=;i<=n;i++) if(vis[i]==-) ok=;//不联通
if(ok) puts("YES");
else puts("NO");
}
return ;
}
 

HDU 5971 二分图判定的更多相关文章

  1. The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间

    /*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 |  C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...

  2. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

  3. hdoj 3478 Catch(二分图判定+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...

  4. CF687A. NP-Hard Problem[二分图判定]

    A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. COJ 0578 4019二分图判定

    4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...

  6. UVA 11080 - Place the Guards(二分图判定)

    UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...

  7. poj2942 Knights of the Round Table,无向图点双联通,二分图判定

    点击打开链接 无向图点双联通.二分图判定 <span style="font-size:18px;">#include <cstdio> #include ...

  8. hdu 5727 二分图+环排列

    Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. HDU2444(KB10-B 二分图判定+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

随机推荐

  1. [luogu 3369]普通平衡树(fhq_treap)

    题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数 删除x数(若有多个相同的数,因只删除一个) 查询x数的排名(排名定义为比当前数小的数的个数+1.若有多 ...

  2. vscode 常用插件安装

    设置中文语言使用快捷键[Ctrl+Shift+P],弹出的搜索框中输入[configure language],然后选择搜索出来的[Configure Display Language],locale ...

  3. 一张图掌握移动Web前端所有技术(大前端、工程化、预编译、自动化)

    你要的移动web前端都在这里! 大前端方向:移动Web前端.Native客户端.Node.js. 大前端框架:React.Vue.js.Koa  跨终端技术:HTML 5.CSS 3.JavaScri ...

  4. Miner3D Enterprise 企业版

    ——极致的视觉数据挖掘和知识发现解 Miner3D Enterprise 企业版是一个有力的综合数据驱动的三维可视化和数据分析解决方案.金融师.药剂师.生物技术或化学材质科研人员.地质学家.石油开采专 ...

  5. android获取https证书

    最近碰到一个问题, 有朋友问android这边能不能拿到服务器下发的证书,意思就是   自签名证书的https接口,在请求的时候,也没有添加自签名证书进信任列表,直接去发https请求,按照正常htt ...

  6. https验证新发现-老知识

    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); 可以设置https全局的域名校验规则 HttpsURLConnecti ...

  7. pat甲级1123

    1123 Is It a Complete AVL Tree(30 分) An AVL tree is a self-balancing binary search tree. In an AVL t ...

  8. linux 命令——27 chmod

    chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法. 一种是包含字母和操作符表达式的文字设定法: 另一种是包含数字的数字设定法. Linux系统中 ...

  9. Android从本地选择图片文件转为Bitmap,并用zxing解析Bitmap

    如何从本地选择图片文件 使用Intent调用系统相册后,onActivityResult函数返回的是Uri格式的路径 /** * 打开系统相册 */ private void openSysAlbum ...

  10. go语言,安装包fetch error 问题解决方案

    最近需要安装grequests,出现了下面的error [fdf@zxmrlc ~]$ go get github.com/levigross/grequests package golang.org ...