#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 lock
for (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。
*/
相关推荐
用Python实现四叉树(quad tree)
import numpy as np #正方形类 class square: #lx、ly为左上角坐标(x对应行号,y对应列号),rx、ry为右下角坐标 def __init__(self,lx,ly,rx,ry): self.lx=lx self.ly=ly self.rx=rx self.ry=ry #检查该矩阵中是否满足条件 #参数:原矩阵,阈值 #返回值:布尔类型 def check(s
【动态规划】背包题目总结
01背包问题 模板题 acw 2. 01背包问题 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1005; int v[N],w[N],dp[N]; int main() { int n,vv;cin>>n>>vv; for(int i=0;i<n;i++) { cin>>w[i]>>v[i]; } for(int i
ThunderScope开源示波器
4CH,1GSa/S 开源示波器。前端很简洁,BUF802+LMH6518,ADC是HMCAD1511,用Xilinx A7 FPGA进行控制,数据通过PCIE总线传输到上位机处理。目前这个项目已经被挂到了Xilinx官网,强。设计日志:https://hackaday.io/project/180090-thunderscope开源地址:https://github.com/EEVengers/ThunderScope。
Codeforces-766D-The Door Problem(2-SAT-并查集解)
题目链接:Codeforces-766D-The Door Problem 首先可以知道一个钥匙只能使用0或1次。使用多次时与使用0或1次等效。 如果一个门状态是1,那么与这个门关联的两个钥匙要么都使用1次,要么都使用0次。 如果一个门状态是0,那么一个钥匙使用1次,另一个钥匙使用0次。 用u表示钥匙u使用0次,用u+m表示钥匙u使用1次。 然后使用并查集维护。如果u和u+m在同一个集合
博途AI助手演示,完成简单且重复的梯形图代码,并导入到博途
自写个博途AI助手,下面演示AI帮我生成完善多个模拟量输入转换的代码,
Qoder保姆级教程:从安装到多模型接入,全面平替Codex
AI编程正从命令行工具走向AI原生IDE,自然语言驱动Agent生成项目文件、多文件联动修改,已成为开发者提效的新范式。传统CLI工具如Codex虽能力强大,但环境配置复杂、模型绑定封闭,让不少用户望而却步。Qoder作为AI原生IDE,以低门槛、可视化、多模型自由切换为特点,将Agent的文件操作、运行调试、画布预览集成在编辑器内,让“从0写网站”这类任务变得直观可控。文章从概念、原理、技术价值与应用场景切入,围绕Codex平替这一需求,系统讲解Qoder的安装选型、项目实操、接入DeepSeek等第三方
D. The Door Problem
Moriarty has trappednpeople inndistinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors...
Codeforces Round #400 (Div. 1 + Div. 2, combined)D - The Door Problem(2-sat)
D. The Door Problemtime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard outputMoriarty has trapped n people in n distinct rooms in a hotel. Some rooms are
2026美赛数学建模竞赛 MCM C题:与星共舞的数据 问题一 粉丝投票估计模型 详细解题思路和代码
2026美赛数学建模竞赛 MCM C题:与星共舞的数据 问题一 粉丝投票估计模型 详细解题思路和代码.。开发一个(或多个)数学模型,用于估算每位选手在他们参赛的各周的粉丝投票数(这是未知且严格保密的)。您的模型是否能正确估算出导致每周淘汰结果一致的粉丝投票数?提供一致性度量。您估算出的粉丝投票总数有多少确定性?这种确定性对于每位选手/每周是否总是相同?为您的估算提供确定性度量。
金融领域强化学习在高频交易中的应用
强化学习(Reinforcement Learning,简称RL)是一种机器学习范式,通过智能体与环境的交互来学习策略,以最大化累计奖励。与监督学习和无监督学习不同,强化学习依赖于动态的反馈机制,智能体通过试错不断优化决策过程。高频交易(High-Frequency Trading,简称HFT)是指在极短时间内进行的大量金融交易,通常利用算法和计算机系统自动执行交易策略。高频交易依赖于高速的数据处理和决策能力,以捕捉市场中的微小价格波动。状态(State):环境在某一时刻的观测,反映了系统的当前情况。
codeforces round 400 D The Door Problem 2-SAT
/* 题目描述:有n道门,m个开关,每道门由m个开关中的两个控制,若门的状态是0(关),那么改变控制这道门的一个开关之后,门的 状态就变为1(开),若门的状态是1(开),那么改变控制这道门的一个开关之后,门的状态就变为0(关)。 现已知n道门的初始状态,以及m个开关分别控制哪些门,问能不能通过按下某些开关,使得全部门的状态都变为1。
特别章节-0.1 SolidWorks导出机械臂的URDF模型各个关节坐标系设置
通过Solidworks导出机械臂的URDF模型文件,建立机械臂的各个关节坐标系的规则以及注意点,详细步骤
Codeforces Round #400 D. The Door Problem(2-sat)
题目链接:Codeforces Round #400 D. The Door Problem 题意: 有n扇门,每扇门有个初始状态,并且受两个开关控制。 现在给你m个开关控制门的信息,每个开关能将它所控制的门的状态翻转。 问能不能通过一定操作,将所以的门的状态都处于开的情况。 题解: 这题用2sat,也可以用并查集判断联通块。这里我用2sat。 因为一个开关可以控制多扇门,而每个门只...
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
IMSL CNL 7.0.0 (x86-64)Crack
IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件
ICM Technex 2017 and Codeforces Round 400 D. The Door Problem 【2-SAT】
个人练习记录
WINCC7.3破解文件
WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!
Codeforces Round #400 (Div.1+Div.2) D. The Door Problem【2-SAT】
传送门:CF776 D / NEFU 2041 题意 有n个门,有些是开的,有些是关的,有m个开关控制这些门,一个开关可以控制多个门,但是每个门都被恰好2个开关控制。开关的具体作用是,将所有被控制门的状态取反。是否可以通过开关实现所有门都打开? 思路 本题关键在于“每个门都被恰好2个开关控制”。 那么一个门就是一个限制条件,根据门的初始状态,得到这两个开关到底是选还是不选。如果门初始是开,那么两个开关都选或者都不选;如果门初始是关,那么两个开关中只能选一个。 于是题目就转换为:总共n个限制条件,讨论m个点的
Codeforces Round #400 D. The Door Problem (建图+搜索)
DescriptionMoriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the
ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 并查集
题目:https://codeforces.com/contest/776/problem/D 题意: 有n个房间,由m个开关控制。每个房间一定是由两个开关控制。每个房间有一个初始的是否解锁的状态。问你能否让所有房间都解锁。 题解: 若控制一个房间的开关为a,b。一个开关若开为a,不开为a+m。则若房间原来开着,就为(a,b)或(a+m,b+m)。原来没开就为(a,b+m)或(a+m,b)。...
ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ...
Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem(并查集或2-SAT)
题目链接:https://codeforces.com/contest/776/problem/D 题目大意:有n扇门,刚开始有的开着有的关着,有m个开关可同时改变多个门的状态,问是否能通过这些开关是所有门同时打开。 题目思路: 并查集做法:由于题目有个限制条件是一扇门最多被两个开关控制,所以可以用并查集。将按钮没按作为前m个,按了作为后m个,那么当门之前是开着的时候,控制它的按...
Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem(二分染色?/2-sat,好题)
题目链接 D. The Door Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Moriarty has trapped n people i
ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem(种类并查集)
题目链接 思路:种类并查集模板题,如果i表示关,i+m就是它的对立面就是开。 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn =1e5+5; int n,m,pos,t,a[maxn],father[maxn<<1]; vector<int>...
Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 开关--并查集
传送门 题意:给你n个门,和m组开关,每扇门都有两个开关控制,每个开关控制x扇门,如果选择了某组开关,则使这组开关里的每个开关控制的所有的门按状态取反,问你是否能使得所有的门状态为1 做法:确实吊呀,因为每个门题目保证是由两组开关控制的,用x代表不动,x+m代表动这个开关。 那么当第i扇门关着,那就用u和v+m或者u+m和v。 如果是开着,那就用u和v或者u+m和u+m。
Codeforces Round #400 (Div. 1 + Div. 2, combined) 776D. The Door Problem(待翻译)
时间限制:1S / 空间限制:256MB 【在线测试提交传送门】【问题描述】 Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the ho
ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 扩展域并查集
#include<bits/stdc++.h> using namespace std; #define X first #define Y second #define eps 1e-2 #define gcd __gcd #define pb push_back #define PI acos(-1.0) #define lowbit(x) (x)&(-x) #define bug printf("!!!!!\n"); #define mem(x,y) memset(x,y,s
Codeforces Round #400 (Div. 1 + Div. 2, combined)D. The Door Problem【2-sat Tarjan+思维建图】
D. The Door Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Moriarty has trapped n people in n dist
ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 解题报告
A:A Serial Killer 1 #include <iostream> 2 //#include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #inc...
5872




被折叠的 条评论
为什么被折叠?



