#include <bits/stdc++.h> using namespace std; const int N = 100010; int h[N], e[N], ne[N], w[N], idx; int color[N]; int n, m; void add(int a, int b, int c) { e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++; } bool dfs(int u, int c) { color[u] = c; for(int i = h[u]; i != -1; i = ne[i]) { int j = e[i]; if(color[j]) { if(color[j] == c) return false; } else { if(!dfs(j,3-c)) return false; } } return true; } int main() { scanf("%d%d",&n,&m); memset(h,-1,sizeof h); while(m -- ) { int a,b,c; scanf("%d%d%d",&a,&b,&c); add(a,b,c),add(b,a,c); } bool flag = true; for(int i = 1; i <= n; i++) { if(color[i]) continue; if(!dfs(i,1)) { flag = false; break; } } if(flag) puts("Yes"); else puts("No"); return 0; }