#include <bits/stdc++.h>
const int MAXN = 3e5, MAXQ = 5e5, MAXLG = 18;
int n, q, qu[MAXQ + 5], qv[MAXQ + 5], qw[MAXQ + 5];
bool ans[MAXQ + 5], sum[MAXN + 5];
int ecnt, head[MAXN + 5], dep[MAXN + 5], fa[MAXN + 5][MAXLG + 5];
int dfc, dfn[MAXN + 5], siz[MAXN + 5];
struct Edge {
  int to, val, nxt;
} graph[MAXN * 2 + 5];
inline void link(const int u, const int v, const int w) {
  graph[++ecnt] = {v, w, head[u]}, head[u] = ecnt;
  graph[++ecnt] = {u, w, head[v]}, head[v] = ecnt;
}
struct DSU {
  int fa[MAXN + 5], siz[MAXN + 5];
  inline void init() {
    for (int i = 1, repi = n; i <= repi; ++i) siz[fa[i] = i] = 1;
  }
  inline int find(const int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
  inline bool unite(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return false;
    if (siz[x] < siz[y]) x ^= y ^= x ^= y;
    return siz[fa[y] = x] += siz[y], true;
  }
} dsu;
struct BinaryIndexTree {
  int val[MAXN + 5];
  inline void upd(int x, const int k) {
    for (; x <= n; x += x & -x) val[x] += k;
  }
  inline int sum(int x) {
    int ret = 0;
    for (; x; x -= x & -x) ret += val[x];
    return ret;
  }
} bit;
inline void init(const int u) {
  dep[u] = dep[fa[u][0]] + 1, dfn[u] = ++dfc, siz[u] = 1;
  for (int j = 1; fa[u][j - 1]; fa[u][j] = fa[fa[u][j - 1]][j - 1], ++j)
    ;
  for (int i = head[u], v; i; i = graph[i].nxt) {
    if ((v = graph[i].to) != fa[u][0]) {
      fa[v][0] = u, sum[v] = sum[u] ^ graph[i].val;
      init(v), siz[u] += siz[v];
    }
  }
}
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) u ^= v ^= u ^= v;
  for (int i = MAXLG, peri = 0; i >= peri; --i)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = MAXLG, peri = 0; i >= peri; --i)
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i], v = fa[v][i];
    }
  return fa[u][0];
}
int main() {
  scanf("%d %d", &n, &q), dsu.init();
  for (int i = 1, repi = q; i <= repi; ++i) {
    scanf("%d %d %d", &qu[i], &qv[i], &qw[i]);
    if (dsu.unite(qu[i], qv[i])) {
      ans[i] = true, link(qu[i], qv[i], qw[i]);
    }
  }
  for (int i = 1, repi = n; i <= repi; ++i)
    if (!fa[i][0]) init(i);
  for (int i = 1, repi = q; i <= repi; ++i)
    if (!ans[i]) {
      int u = qu[i], v = qv[i], w = lca(u, v);
      if ((sum[u] ^ sum[v]) == qw[i] ||
          bit.sum(dfn[u]) + bit.sum(dfn[v]) - 2 * bit.sum(dfn[w]))
        continue;
      ans[i] = true;
      while (u != v) {
        if (dep[u] < dep[v]) u ^= v ^= u ^= v;
        bit.upd(dfn[u], 1), bit.upd(dfn[u] + siz[u], -1), u = fa[u][0];
      }
    }
  for (int i = 1, repi = q; i <= repi; ++i) puts(ans[i] ? "YES" : "NO");
  return 0;
}
