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 ...
随机推荐
- ACM 第二天
A - Mishka and Contest Mishka started participating in a programming contest. There are n problems i ...
- iOS- iPad里有趣的UIPopoverController
效果: 1.对UIPopoverController的简单概述 1.1 UIPopoverController是在iPad开发中常用的一个组件(在iPhone上不允许使用),使用非常简单 1.2 ...
- JSP在页面加载时调用servlet的方法
方法:先在JS里面写一个调用servlet的事件(可以利用ajax),然后利用<body>标签的onload调用这个事件. 代码如下: jsp文件代码如下: <%@ page lan ...
- 转 Redis集群技术及Codis实践
转 Redis集群技术及Codis实践 转自 :http://blog.51cto.com/navyaijm/1637688 codis开源地址:https://github.com/CodisLa ...
- react项目开发入门
v16.2.0 在html头部引入react相关js文件 <!-- react核心库--><script src="../static/react/react.produc ...
- C#Color颜色表
Color.AliceBlue 240,248,255 Color.LightSalmon 255,160,122 Color.AntiqueWhite 250,235,215 Color.Light ...
- 提升MyEclipse运行速度
修改MyEclipse.ini文件中的,将-vmargs后面的参数修改为 -Xms256m -Xmx768m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:Max ...
- 【Python】ORM框架SQLAlchemy的使用
ORM和SQLAlchemy简介 对象关系映射(Object Relational Mapping,简称ORM),简单的来说,ORM是将数据库中的表与面向对象语言中的类建立了一种对应的关系.然后我们操 ...
- springBoot @EnableAutoConfiguration深入分析
1.新建一个项目中需要提供配置类 2.在META-INF/spring.factorties在文件中配置 org.springframework.boot.autoconfigure.EnableAu ...
- snmpwalk的报文检测
1.先用nc起一个监听的端口,然后看报文是不是正确的: 注:nc是一个模拟各种网络协议的东西,模拟服务器.客户端等: 2.触发告警,让他发报文: 3.用nc模拟一个服务端,启动一个udp的端口163: ...