#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
const int N = 1e6 + 5;
int n;
namespace LCT {
int tag[N], v[N], siz[N], ch[N][2], fa[N], st[N], cov[N];
void init(int n) {
  for (int i = 1; i <= n; i++) cin >> v[i];
}
inline int get(int x) { return ch[fa[x]][1] == x; }
inline int isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void pushup(int rt) {
  cov[rt] = cov[ch[rt][0]] | cov[ch[rt][1]] | v[rt];
  siz[rt] = siz[ch[rt][0]] + siz[ch[rt][1]] + 1;
}
void pushdown(int rt) {
  if (tag[rt]) {
    tag[ch[rt][0]] ^= 1, tag[ch[rt][1]] ^= 1;
    swap(ch[rt][0], ch[rt][1]);
    tag[rt] = 0;
  }
}
void rotate(int x) {
  int f = fa[x], ff = fa[f], w = get(x), ww = get(f);
  if (!isroot(f)) ch[ff][ww] = x;
  fa[ch[f][w] = ch[x][w ^ 1]] = f;
  fa[ch[x][w ^ 1] = f] = x;
  fa[x] = ff;
  pushup(f), pushup(x);
}
void splay(int x) {
  int top = 0, t = x;
  st[++top] = x;
  while (!isroot(t)) st[++top] = (t = fa[t]);
  while (top) pushdown(st[top--]);
  while (!isroot(x)) {
    if (!isroot(fa[x])) {
      if (get(x) == get(fa[x]))
        rotate(fa[x]);
      else
        rotate(x);
    }
    rotate(x);
  }
  pushup(x);
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) {
    splay(x), ch[x][1] = y, pushup(x);
  }
}
void makeroot(int x) {
  access(x);
  splay(x);
  tag[x] ^= 1;
}
void split(int x, int y) {
  makeroot(x);
  access(y);
  splay(y);
}
int findroot(int x) {
  access(x), splay(x);
  while (ch[x][0]) x = ch[x][0], pushdown(x);
  splay(x);
  return x;
}
void link(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) fa[x] = y;
}
void cut(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) return;
  if (ch[x][1] == y && !ch[y][0]) fa[y] = ch[x][1] = 0;
}
void dfs(int rt) {
  if (rt > n) v[rt] = 1;
  if (ch[rt][0]) dfs(ch[rt][0]);
  if (ch[rt][1]) dfs(ch[rt][1]);
  cov[rt] = cov[ch[rt][0]] | cov[ch[rt][1]] | v[rt];
}
void change(int x, int y) {
  split(x, y);
  dfs(y);
}
int query(int x, int y) {
  split(x, y);
  return cov[y];
}
};  // namespace LCT
int f[N], s[N];
int find(int x) {
  if (x == f[x]) return x;
  int t = f[x];
  f[x] = find(f[x]);
  s[x] ^= s[t];
  return f[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) f[i] = i;
  int tot = n;
  for (int i = 1, u, v, x; i <= q; i++) {
    cin >> u >> v >> x;
    if (find(u) != find(v)) {
      int fu = f[u], fv = f[v];
      s[fu] = s[u] ^ s[v] ^ x;
      f[fu] = fv;
      tot++;
      LCT::link(u, tot);
      LCT::link(v, tot);
      cout << "YES\n";
    } else {
      if ((s[u] ^ s[v] ^ x) == 0 || LCT::query(u, v))
        cout << "NO\n";
      else {
        cout << "YES\n";
        LCT::change(u, v);
      }
    }
  }
  return 0;
}
