hdu 5971 Wrestling Match
来源:互联网 发布:北京行知实践园作文 编辑:程序博客网 时间:2024/06/06 05:55
http://acm.hdu.edu.cn/showproblem.php?pid=5971
给出一些好人与坏人的名单,再给出match的对战表,每次必定是好人和坏人对战,问最终根据已知是否矛盾,涂色问题,bfs把每个人染上颜色遇到矛盾的地方跳出即可。因为没加上eof超时了很多次,甚至开始怀疑人生。
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include <vector>#include<iomanip>#include<queue>using namespace std;int n,m,x,y;vector<int>ma[1111];int ans[1111];int flag=1;void dfs(int p,int sx){queue<int> q; q.push(p); int ss;while(!q.empty()){ss=q.front();q.pop();for(int i=0;i<ma[ss].size();i++){int k=ma[ss][i];if(ans[k]==ans[ss]){flag=0;return;}if(ans[k]==0){ans[k]=0-ans[ss];q.push(k);} }}}int main(){while(~scanf("%d%d%d%d",&n,&m,&x,&y)){ flag=1; memset(ans,0,sizeof(ans)); int i,j; int a,b; for(i=0;i<=n;i++) ma[i].clear(); for(i=1;i<=m;i++) { scanf("%d%d",&a,&b); ma[a].push_back(b); ma[b].push_back(a); } for(i=1;i<=x;i++) { scanf("%d",&a); if(ans[a]==-1)flag=0; ans[a]=1; dfs(a,1); } for(i=1;i<=y;i++) { scanf("%d",&a); if(ans[a]==1)flag=0; ans[a]=-1; dfs(a,-1); } if(flag==0) { cout<<"NO"<<endl; continue; } for(i=1;i<=n;i++) { if(ans[i]==0) { if(ma[i].size()==0)continue; ans[i]=1; dfs(i,1); } } //for(i=1;i<=n;i++) //cout<<ma[i].size()<<" "; //cout<<endl; for(i=1;i<=n;i++) { if(ans[i]==0)flag=0; } if(flag==0)cout<<"NO"<<endl; else cout<<"YES"<<endl;}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)
- (Copy)设计投入方案
- POJ1298(模拟题)
- 高性能spark
- jsp应用实例-网上答题评测系统
- 二叉树的遍历和线索线索二叉树
- hdu 5971 Wrestling Match
- Android实现bitmap指定区域滑动截取
- python面向对象
- IDEA导入elipse构建的github项目
- 单链表(不含头结点)--尾插,查找
- 进程间通信
- bzoj 1486: [HNOI2009]最小圈
- c++知识点----定义抽象基类(纯虚函数)
- Common Subsequence dp