codeforces Round 400 D-The Door Problem
来源:互联网 发布:网络聊天工具 编辑:程序博客网 时间:2024/05/21 19:01
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N=100000+10;const LL INF=1000000000000000LL;vector<int>a[N];int r[N];int n,m;int bcj[N],s[N];int find(int x){ if (bcj[x]==x) return x; int fx=find(bcj[x]); s[x] = ( s[x] + s[ bcj[x] ] )%2; return bcj[x]=fx;}int Union(int x,int y,int z){int fx=find(x); int fy=find(y);bcj[fx]=fy;s[fx]=(z-s[x]-s[y]+2)%2;}int main(){ //-freopen("1.txt","r",stdin);scanf("%d%d",&n,&m);for (int i=1;i<=n;i++)scanf("%d",&r[i]);//1 open ; 0 lockfor (int i=1;i<=m;i++){int x;scanf("%d",&x);for (int j=0;j<x;j++){int y;scanf("%d",&y);a[y].push_back(i);}}for (int i=1;i<=m;i++)bcj[i]=i,s[i]=0;for (int i=1;i<=n;i++){if (find(a[i][0])==find(a[i][1])){ if ((s[ a[i][0] ]+s[ a[i][1] ])%2!=1-r[i]){ puts("NO"); return 0; }}else Union(a[i][0],a[i][1],1-r[i]);}puts("YES");//system("pause");return 0;}/*题目: http://codeforces.com/contest/776/problem/D题意: n个房间,有些门是开的(1),有些门是关的(0);现有m个开关,可以控制xi个房间。每个房间恰有两个开关控制。问是否能使所有门都开。(n≤10^5,m≤10^5)题解: 将开关看成点,房间看成边(连接两个开关),若房间开着则边权为1,否则为0。对点用0-1染色,边权为1的点颜色相同,边权为0的颜色相反。若能染遍所有点,则可行。 或者:同上建图,采用并查集求解,s[x]表示x与父亲的关系,相同为0,不同为1。*/
0 0
- codeforces Round 400 D-The Door Problem
- Codeforces Round #400 D. The Door Problem (建图+搜索)
- codeforces round 400 D The Door Problem 2-SAT
- Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 开关--并查集
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776D. The Door Problem(待翻译)
- 【codeforces 776D】The Door Problem
- CodeForces-776D The Door Problem
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D. The Door Problem【2-sat Tarjan+思维建图】
- Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem(二分染色?/2-sat,好题)
- Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT、并查集
- The Door Problem CodeForces
- Codeforces 776D The Door Problem 二分图判定
- codeforces-776D-The Door Problem(染色+建边+dfs)
- Codeforces-766D-The Door Problem(2-SAT-并查集解)
- 【Codeforces 776 D The Door Problem】+ 并查集
- CodeForces 776D The Door Problem【并查集】
- Codeforces 776D The Door Problem 【并查集】
- codeforces 776D The Door Problem(带权并查集)
- Word2003 奇偶页页眉页脚不同,页码设置问题
- Android开发中在drawable中自定义绘制图形作为按钮背景.txt
- c语言对文件的操作
- poj 2828 线段树+单点更新
- 1003. Emergency (25) PAT 甲级
- codeforces Round 400 D-The Door Problem
- SQL查看“学生成绩”数据库的信息
- QT中QString与string的转化,解决中文乱码问题
- 基于python和numpy的KNN手写识别
- Tomcat的 Document base ……does not exist or is not a readable directory错误
- 细说自动化运维的前世今生
- 4.运行freeswitch
- #199. 守护糖果
- 深度学习解决多视图非线性数据特征融合问题