Wrestling Match

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

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
虽说是道水题但是能够一遍过还是挺爽的。
 
题意:有n个选手,m场比赛,x个著名好选手,y个著名坏选手,每场比赛都是一名号选手与一名坏选手对打。问在这些条件下是否让所有的选手都拥有身份。(非好即坏
 
解题思路:当时想的就是搜索,先把与x相关的搜一遍,确认关系,再把与y相关的搜一遍,最后剩下都不相关的看是否有比赛,如果有比赛,随机设1名为好选手,搜索和他相关的选手,直到所有的比赛都遍历完。
 
ac代码:
  1 #include <cstdio>
2 #include <iostream>
3 #include <cmath>
4 #include <cstring>
5 #include <algorithm>
6 #define ll long long
7 const int maxn = 1000+10;
8 using namespace std;
9 int mp[maxn][maxn];
10 int vis[maxn];
11 int n,m,x,y;
12
13 int ed=0; //ed==1的时候,说明该选手没有比赛,ed==2的时候,说明遇到两个同类型的选手在一起比赛,直接f=1,输出NO
14 void df(int a,int s)
15 {
16 int i=1;
17 if(ed) return;
18 for(i=1;i<=n;++i)
19 {
20 if(mp[a][i] && vis[i]!=s && vis[i]!=0)
21 {
22 ed=2;
23 // printf("\n%d %d\n",a,i);
24 break;
25 }
26 if(mp[a][i] && !vis[i])
27 {
28 vis[i]=s;
29 if(s==1)
30 df(i,2);
31 else
32 df(i,1);
33 }
34 }
35 if(i==n+1)
36 {
37 ed=1;
38 return;
39 }
40 }
41 int main() {
42
43 while(~scanf("%d%d%d%d",&n,&m,&x,&y))
44 {
45 memset(mp,0,sizeof(mp));
46 memset(vis,0,sizeof(vis));
47 int a,b;
48 for(int i=0;i<m;++i)
49 {
50 scanf("%d%d",&a,&b);
51 mp[a][b]=1;
52 mp[b][a]=1;
53 }
54
55 int f=0;
56
57 for(int i=0;i<x;++i)
58 {
59 scanf("%d",&a);
60 vis[a]=1;
61 ed=0;
62 df(a,2);
63 }
64
65 if(ed==2) f=1;
66
67 for(int i=0;i<y;++i)
68 {
69 scanf("%d",&b);
70 vis[b]=2;
71 ed=0;
72 df(b,1);
73 }
74
75 if(ed==2) f=1;
76
77 for(int i=1;i<=n;++i)
78 {
79 for(int j=1;j<=n;++j)
80 {
81 ed=0;
82 if(mp[i][j] && vis[i]==0 && vis[j]==0)
83 {
84 vis[i]=1;
85 df(i,2);
86 }
87 }
88 }
89
90 for(int i=1;i<=n;++i)
91 {
92 if(vis[i]==0)
93 {
94 f=1;
95 break;
96 }
97 }
98 if(!f)
99 printf("YES\n");
100 else
101 printf("NO\n");
102 }
103 return 0;
104 }

最新文章

  1. Android之ListView的getItemViewType和getViewTypeCount
  2. nyoj-204
  3. spark textFile 困惑与解释
  4. 区间合并 --- Codeforces 558D : Gess Your Way Out ! II
  5. 夺命雷公狗---DEDECMS----31dedecms数据库创建一张表完成curl操作
  6. 车载凯立德导航地图更新以及DSA数据更新方法
  7. Map,HashMap
  8. 接口、抽象类、方法复写、类Equals方法重写
  9. 数据挖掘10大算法(1)——PageRank
  10. Leetcode 338. Counting Bits
  11. Mysql JDBC Url参数说明useUnicode=true&amp;characterEncoding=UTF-8
  12. LNMP系统服务搭建过程详解
  13. 获取camera截屏图片
  14. MDK C++中对内联的极度优化
  15. php数组排序和查找的算法
  16. 大数据批量导入,解决办法,实践从定时从 sqlserver 批量同步数据到 mySql
  17. 随笔:关于去年的WordPress建站的回忆
  18. GWAS研究中case和control的比例是有讲究的?
  19. 奇yin技巧
  20. .NET CORE学习笔记系列(1)——ASP.NET MVC Core 介绍和项目解读

热门文章

  1. mybatis中传集合时 报异常 invalid comparison: java.util.Arrays$ArrayList and java.lang.String
  2. 使用Logback日志
  3. 第2章_神经网络入门_2-5&amp;2-6 数据处理与模型图构建
  4. Kubernetes集群管理工具kubectl命令技巧大全
  5. IDEA 简介
  6. [从源码学设计] Flume 之 memory channel
  7. 匿名字段 内嵌结构体 interface作为struct field 匿名接口
  8. Eclipse+Maven+Spring
  9. 404 GET /nbextensions/jupyter-js-widgets/extension.js
  10. Docker系列(一)Docker概述,核心概念讲解,安装部署