#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long inf = 8e18;
const int LOG = 20;
long long pw(long long a, long long b, long long M = mod, long long ret = 1) {
  while (b) {
    ret = ret * (b & 1 ? a : 1) % M, a = a * a % M, b >>= 1;
  }
  return ret;
}
int n, q, ptr, Ans[N], fir[N], sec[N], X[N], par[N], P[LOG][N], Xor[N], St[N],
    Fi[N], H[N];
vector<int> G[N];
int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); }
int unify(int v, int u) {
  v = get(v), u = get(u);
  if (v == u) return 0;
  par[u] = v;
  return 1;
}
void dfs(int v) {
  St[v] = ++ptr;
  for (int T = 1; T < LOG; T++) {
    P[T][v] = P[T - 1][P[T - 1][v]];
  }
  for (auto id : G[v]) {
    int u = fir[id] ^ sec[id] ^ v;
    if (St[u]) continue;
    H[u] = H[v] + 1;
    P[0][u] = v;
    Xor[u] = Xor[v] ^ X[id];
    dfs(u);
  }
  Fi[v] = ptr;
}
inline int LCA(int v, int u) {
  if (H[v] > H[u]) swap(u, v);
  int del = H[u] - H[v];
  for (int T = LOG - 1; ~T; T--) {
    if (del >> T & 1) {
      u = P[T][u];
    }
  }
  if (v == u) return v;
  for (int T = LOG - 1; ~T; T--) {
    if (P[T][v] != P[T][u]) {
      v = P[T][v];
      u = P[T][u];
    }
  }
  return P[0][v];
}
int seg[N << 2], lz[N << 2];
void upd(int l, int r, int x, int v = 1, int tl = 1, int tr = n) {
  if (l > tr || r < tl || l > r) return;
  if (l <= tl && tr <= r) {
    seg[v] = max(seg[v], x);
    lz[v] = max(lz[v], x);
    return;
  }
  int mid = (tl + tr) >> 1;
  upd(l, r, x, v << 1, tl, mid), upd(l, r, x, v << 1 | 1, mid + 1, tr);
  seg[v] = max(seg[v << 1], seg[v << 1 | 1]);
}
int ask(int p, int v = 1, int tl = 1, int tr = n) {
  if (tl == tr) {
    return seg[v];
  }
  int mid = (tl + tr) >> 1;
  if (p <= mid) return max(lz[v], ask(p, v << 1, tl, mid));
  return max(lz[v], ask(p, v << 1 | 1, mid + 1, tr));
}
int main() {
  iota(par, par + N, 0);
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &fir[i], &sec[i], &X[i]);
    if (unify(fir[i], sec[i])) {
      Ans[i] = 1;
      G[fir[i]].push_back(i);
      G[sec[i]].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!St[i]) {
      dfs(i);
    }
  }
  for (int i = 1; i <= q; i++) {
    if (Ans[i]) continue;
    int lca = LCA(fir[i], sec[i]);
    if ((Xor[fir[i]] ^ Xor[sec[i]] ^ X[i]) == 0) {
      continue;
    }
    int v = fir[i], u = sec[i];
    if (ask(St[v]) <= H[lca] && ask(St[u]) <= H[lca]) {
      Ans[i] = 1;
      while (v ^ u) {
        if (H[u] < H[v]) {
          swap(u, v);
        }
        upd(St[u], Fi[u], H[u]);
        u = P[0][u];
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    if (Ans[i]) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
