HDU 5971 Wrestling Match(深搜)
来源:互联网 发布:壁纸软件下载 编辑:程序博客网 时间:2024/05/16 19:34
这题题目看了谷歌翻译都没懂。。看到别人的博客发现就是一个染色问题
题意:主要就是有n个人,进行了m次比赛,其中已经知道的有x个好人,y个坏人
然后让你判断能不能把好人和坏人完全分开
首先先对知道身份的人进行查找,然后对没有出现的或者没有遍历到的人搜索
最后输出
唯一不明白的就是样例1的输出。。。然后自己限制一个x==0&&y==0 cout<<"NO";就过了
不懂为什么
#include<iostream>#include<cstdio>#include<math.h>#include<cstring>#include<algorithm>#include<queue>#include<set>#include<vector>using namespace std;int n,m,x,y;vector<int> v[1001];int col[1001]={0};int flag=1;void dfs(int num){for(int i=0;i<v[num].size();i++){int fz=v[num][i];if(col[num]==col[fz]){ flag=0; return;}if(col[fz]==0){col[fz]=col[num]==1?-1:1;dfs(fz);}}}int main(){while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){flag=1;for(int i=1;i<=n;i++) v[i].clear(),col[i]=0;for(int i=0;i<m;i++){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);col[a]=1;}for(int i=0;i<y;i++){int a;scanf("%d",&a);col[a]=-1;}if(x==0&&y==0){cout<<"NO"<<endl;continue;}for(int i=1;i<=n;i++){if(col[i]!=0&&flag){dfs(i);}}for(int i=1;i<=n;i++){if(col[i]==0&&flag){col[i]=1;dfs(i);}}if(flag==1) cout<<"YES"<<endl;else cout<<"NO"<<endl;}return 0;}
阅读全文
1 0
- HDU 5971 Wrestling Match(深搜)
- hdu 5971 Wrestling Match
- HDU 5971 Wrestling Match
- hdu 5971 Wrestling Match
- hdu 5971Wrestling 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)
- Linux从入门到精通 笔记
- marven发布的时候带上源码
- 1.1顺序表(SeqList)的实现
- 截取字符串
- python 内置函数
- HDU 5971 Wrestling Match(深搜)
- CMD 迁移oracle数据库(远程到本地)
- linux目录总结
- 【数学建模】CUMCM-2014B 创意平板折叠桌 解题思路整理
- gulp打包依赖的模块
- Take it easy
- Android UI绘制流程源码分析
- UVA 10529 浅谈期望动态规划末状态转移推导全方程转移
- COOKIE和SESSION有哪些区别?