哦……
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
using namespace std;
#define MAXN (55)
int tot = 0;
int first[MAXN], nxt[MAXN << 1], d[MAXN];
bool vis[MAXN];
struct edge{
int from, to, cost;
}es[MAXN << 1];
void build(int ff, int tt, int dd)
{
es[++tot] = (edge){ff,tt,dd};
nxt[tot] = first[ff];
first[ff] = tot;
}
bool dfs(int x)
{
vis[x] = 1;
for(int i = first[x]; i != -1; i = nxt[i])
{
int v = es[i].to;
if(vis[v])
{
if(d[v] == (d[x]^es[i].cost)) continue;
else return 0;
}
d[v] = d[x]^es[i].cost;
if(!dfs(v)) return 0;
}
return 1;
}
int main()
{
int T;
cin >> T;
while(T --)
{
memset(first,-1,sizeof(first));
memset(nxt,0,sizeof(nxt));
memset(vis,0,sizeof(vis));
memset(d,0,sizeof(d));
tot = 0;
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; ++ i)
{
int f, t, d;
scanf("%d%d%d", &f, &t, &d);
build(f,t,d); build(t,f,d);
}
bool h = 0;
for(int i = 1; i <= n; ++ i)
if(!vis[i] && !dfs(i))
{h = 1;break;}
printf("%s\n", h?"No":"Yes");
}
return 0;
}