hdoj 5971
Wrestling Match
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2539 Accepted Submission(s): 922
1 3
1 4
3 5
4 5
5 4 1 0
1 3
1 4
3 5
4 5
2
YES
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 }
hdoj 5971的更多相关文章
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
- 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design
题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...
- BFS(八数码) POJ 1077 || HDOJ 1043 Eight
题目传送门1 2 题意:从无序到有序移动的方案,即最后成1 2 3 4 5 6 7 8 0 分析:八数码经典问题.POJ是一次,HDOJ是多次.因为康托展开还不会,也写不了什么,HDOJ需要从最后的状 ...
随机推荐
- ASP.NET Core错误处理中间件[4]: 响应状态码页面
StatusCodePagesMiddleware中间件与ExceptionHandlerMiddleware中间件类似,它们都是在后续请求处理过程中"出错"的情况下利用一个错误处 ...
- 转 5 jmeter性能测试小小的实战
5 jmeter性能测试小小的实战 项目描述 被测网址:www.sogou.com指标:相应时间以及错误率场景:线程数 20.Ramp-Up Period(in seconds) 10.循环次数 ...
- jdk安装简洁版
一.jdk是what? jdk其实是个软件语言开发包,包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具. 没有JDK的话,无法编译Java程序(指java源码.java文件),如果想 ...
- Manachar’s Algorithm
Manachar's Algorithm Longest palindromic substring - Wikipedia https://en.wikipedia.org/wiki/Longes ...
- net.core.somaxconn net.ipv4.tcp_max_syn_backlog
Linux参数-net.core.somaxconn与net.ipv4.tcp_max_syn_backlog_梁海江的博客-CSDN博客_net.ipv4.tcp_max_syn_backlog h ...
- win api 窗口操作-窗口置顶与寻找与激活
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos https://docs.micr ...
- MySQL时间格式转换函数
MySQL DATE_FORMAT() 函数注:当前年份是2018-7-19 SELECT DATE_FORMAT(NOW(),'%Y') ...
- Spark Streaming状态管理函数updateStateByKey和mapWithState
Spark Streaming状态管理函数updateStateByKey和mapWithState 一.状态管理函数 二.mapWithState 2.1关于mapWithState 2.2mapW ...
- Spark调优,性能优化
Spark调优,性能优化 1.使用reduceByKey/aggregateByKey替代groupByKey 2.使用mapPartitions替代普通map 3.使用foreachPartitio ...
- dedecms文章页的上下篇颠倒的问题
dedecms的文章页底下的上下篇,如果按照时间排序的话,最新的一篇应该是最上了,但是底下还是会显示上一篇文章还有,然后下一篇文章没有了,就是颠倒了.如何修改呢. 1.修改include目录下arc. ...