codechef September Challenge 2017 Fill The Matrix



这道题我们发现0就代表相同1代表少1或者大1
那么我们根据题目连边 如果存在1(边权只为或0)个数为奇数的环就是无解
#include<cstdio>
#include<cstring>
#include<algorithm>
const int M=1e6+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int T,n,q,vis[M],c[M];
int first[M],cnt;
bool f;
struct node{int to,next,s;}e[*M];
void ins(int a,int b,int s){e[++cnt]=(node){b,first[a],s}; first[a]=cnt;}
void insert(int a,int b,int s){ins(a,b,s); ins(b,a,s);}
void clear(){
f=true; cnt=;
memset(c,,*(n+));
memset(first,,*(n+));
memset(vis,,*(n+));
}
void dfs(int x){
if(!f) return ; vis[x]=;
for(int i=first[x];i;i=e[i].next){
int now=e[i].to;
if(vis[now]){
if(e[i].s&&c[now]==c[x]) return void(f=false);
if(!e[i].s&&c[now]!=c[x]) return void(f=false);
}
else c[now]=c[x]^e[i].s,dfs(now);
}
}
int main(){
T=read();
while(T--){
int x,y,s;
n=read(); q=read(); clear();
for(int i=;i<=q;i++) x=read(),y=read(),s=read(),insert(x,y,s);
for(int i=;i<=n;i++)if(!vis[i]) dfs(i);
if(f) printf("yes\n");
else printf("no\n");
}
return ;
}
codechef September Challenge 2017 Fill The Matrix的更多相关文章
- codechef September Challenge 2017 Sereja and Commands
———————————————————————————— 这道题维护一下原序列的差分以及操作的差分就可以了 记得倒着差分操作 因为题目保证操作2的l r 小与当前位置 #include<cstd ...
- Codechef September Challenge 2018 游记
Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...
- Codechef September Challenge 2019 Division 2
Preface 这确实应该是我打过的比较水的CC了(其实就打过两场) 但由于我太弱了打的都是Div2,所以会认为上一场更简单,其实上一场Div的数据结构是真的毒 好了废话不多说快速地讲一下 A Eas ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays
https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds
https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out
https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...
- codechef January Challenge 2017 简要题解
https://www.codechef.com/JAN17 Cats and Dogs 签到题 #include<cstdio> int min(int a,int b){return ...
随机推荐
- Internet History
Alan Turing and Bletchley Park Top secret breaking effort(二战破译希特勒密码) 10,000 people at the peak(team ...
- Coredump及调试
1.查看是否打开了coredump lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c #这里可以看到ulimit限制core ...
- web前端之路 - 开篇
一 web发展历程 了解事物的历史有助于我们渐进式的从发展的思路清楚了解事物的来龙去脉. 这里有一篇网文写得比较清晰和完整:https://www.tianmaying.com/tutorial/we ...
- C# 创建Excel或需不安装Office
第一种.Aspose.Cells.dll //如果需要饶过office Excel那么就看我最后的实现方法吧~! //我最后的实现是使用的第三方Aspose.Cells.dll //具了解这个dll一 ...
- lol人物模型提取(四)
在淘宝上联系了一个3d打印服务的卖家,他要我转成stl.obj.xt.xst.igs任意一种格式给他发过去,我就把它转成了obj格式给他发过去了. 然后他那边打开是这样的,没有贴图,看上去模型 ...
- 原生javascript自定义input[type=radio]效果
2018年6月27日 更新 找到最为简单的仅仅使用css3的方案 <!DOCTYPE html> <html lang="en"> <head> ...
- 最近面试前端面试题整理(css部分)
对最近面试的面试题坐下总结: 一,css部分 1,html元素的垂直居中 答案: <div id="box"> <div> 测试 </div> ...
- 添加路由时啥时候是dev啥时候是gw
A qumu ethA1 B 宿主机 ethA2 ethC2 C 树莓派 ethC1 在A和C中都是直接sudo route add default dev ethA1/ethC1 这样做是有问题的 ...
- [OS] 操作系统常考知识点
转自:http://jennica.space/2017/03/21/os-principle/ 大纲如下: 1.操作系统概述2.操作系统运行环境3.进程线程模型4.处理器调度5.同步机制6.存储模型 ...
- 关于Python的 a, b = b, a+b
Python中有一种写法:多个值同时赋给多个变量,如:a, b = b, a+b 1. A写法 a = 0, b = 1 a, b = b, a+b print a, b #结果为:1 1 这种写法, ...