考虑对于第二个操作,显然最多进行一次
对于第一个操作,由于环异或环还是环
所以最多进行不到
m
m
m次
所以次数限制是假的,只用考虑是否可行
考虑先利用第二个操作,使得所有
"
1
"
"1"
"1"边恰好形成若干个环
而若干个环等价于所有点度数为偶数
则即可变成对于点的度数的限制
高斯消元解异或方程即可
复杂度 O ( T n 3 w ) O(T\frac{n^3}{w}) O(Twn3)
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=301;
bitset<N> a[N];
int d[N],lk[N],n,m;
inline bool gauss(){
for(int i=0;i<n;i++){
int ps=i;
for(;ps<n;ps++)if(a[ps][i])break;
if(ps==n)continue;
if(ps!=i)swap(a[ps],a[i]);
for(int j=0;j<n;j++)if(a[j][i]&&j!=i)a[j]^=a[i];
}
for(int i=0;i<n;i++)if(a[i][n]&&!a[i][i])return false;
return true;
}
inline void solve(){
n=read(),m=read();
for(int i=1;i<=m;i++){
int u=read()-1,v=read()-1,w=read();
d[u]^=1,d[v]^=1;
a[u][v]=a[v][u]=1;
lk[u]^=w,lk[v]^=w;
}
for(int i=0;i<n;i++)a[i][i]=d[i],a[i][n]=lk[i];
cout<<(gauss()?"yes":"no")<<'\n';
for(int i=0;i<n;i++)a[i].reset(),lk[i]=d[i]=0;
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
int T=read();
while(T--)solve();
return 0;
}