hdu 5971 Wrestling Match
来源:互联网 发布:淘宝如何退货给卖家 编辑:程序博客网 时间:2024/06/05 03:39
http://acm.split.hdu.edu.cn/showproblem.php?pid=5971
Wrestling Match
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 116 Accepted Submission(s): 65
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 01 31 43 54 55 4 1 01 31 43 54 52
Sample Output
NOYES
#include<cstdio>#include<cstdlib>#include<math.h>#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<set>#include<vector>#include<map>#define ms(x) memset( (x),0,sizeof(x) );using namespace std;typedef long long int ll;map<int,int>mp;vector<int>v[1009];int sum,f;void init(){mp.clear();for(int i = 0;i < 1009;i++) v[i].clear();sum = f = 0;}void dfs(int n,int p){if( f ) return;for(int i = 0;i < v[n].size();i++){if( mp[ v[n][i] ] == p ) {f = 1;return;}if( mp[ v[n][i] ] == 0 ){mp[ v[n][i] ] = -p,sum++;dfs( v[n][i],-p );}}}int main(){//freopen("E:\\workspace\\acm---C++\\acm\\1.txt","r",stdin);int n,m,x,y;while( scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF ){init();while(m--){int a,b;scanf("%d%d",&a,&b);v[a].push_back(b),v[b].push_back(a);}for(int i = 0;i < x;i++){int a;scanf("%d",&a);if( f ) continue;if( mp[a] == -1 ) { f = 1;continue; }if( mp[a] == 0 ) {mp[a] = 1,sum++;dfs(a,1);}}for(int i = 0;i < y;i++){int a;scanf("%d",&a);if( f ) continue;if( mp[a] == 1 ) { f = 1;continue; }if( mp[a] == 0 ){mp[a] = -1,sum++;dfs(a,-1);}}for(int i = 1;i <= n;i++){if( mp[i] == 0 ){if( v[ i ].size() == 0 ){ f = 1;break; }mp[i] = 1,sum++;dfs( mp[i],1 );}}if( n==sum && f == 0 ) puts("YES");else puts("NO");}return 0;}
0 0
- hdu 5971 Wrestling Match
- HDU 5971 Wrestling Match
- hdu 5971 Wrestling Match
- hdu 5971Wrestling Match
- HDU 5971 Wrestling Match(深搜)
- hdu 5971 Wrestling Match(队列)
- HDU 5971 icpc 大连 A Wrestling Match
- HDU 5971 Wrestling Match(dfs)
- HDU 5971 Wrestling Match(染色+暴力)
- -----染色问题 hdu 5971-Wrestling Match
- 【HDU】5971-Wrestling Match 二分染色
- hdoj 5971 Wrestling Match
- HDU 5971 Wrestling Match 2016大连区域赛
- HDU 5971 Wrestling Match(染色体法判断二分图)
- HDU 5971 Wrestling Match (二分图匹配)
- HDU 5971 Wrestling Match(二分图着色)
- HDU 5971 Wrestling Match(二分图染色)
- 文章标题 HDU 5971 : Wrestling Match (2-sat)
- net中String是引用类型还是值类型
- Docker概况与安装
- Scrapy爬取网页并保存到数据库中
- C#时间格式转换为时间戳(互转)
- 汇编从0开始(8)
- hdu 5971 Wrestling Match
- Swift - 在fir.im上发布程序(免费的应用内测托管平台)
- crontab在一秒内刷新多次导致部分脚本不生效的问题分析
- 在Linux中做定时执行
- flex学习笔记
- JAVA 锁机制
- new和malloc的区别
- 初识Linux系统命令
- php接口