#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
const int p = 998244353;
int qp(int x, int y) {
  int res = 1;
  for (int t = x; y; y >>= 1, t = t * t % p)
    if (y & 1) res = res * t % p;
  return res;
}
int u[500003], v[500003], w[500003], Fa[300003];
int find(int x) {
  if (x == Fa[x]) return Fa[x];
  return Fa[x] = find(Fa[x]);
}
int ans[500003];
vector<pair<int, int> > e[300003];
int sz[300003], fa[300003], dep[300003], son[300003], top[300003];
int dfn[300003], inv[300003], lst[300003], tot;
int V[300003];
inline void dfs1(int x) {
  sz[x] = 1;
  for (auto xx : e[x]) {
    int y = xx.first;
    if (y != fa[x]) {
      if (y == fa[x]) continue;
      fa[y] = x, dep[y] = dep[x] + 1, V[y] = V[x] ^ xx.second, dfs1(y),
      sz[x] += sz[y];
      (sz[y] > sz[son[x]]) && (son[x] = y);
    }
  }
}
inline void dfs2(int x, int tp) {
  top[x] = tp, dfn[x] = ++tot, inv[tot] = x;
  if (son[x]) dfs2(son[x], tp);
  for (auto xx : e[x]) {
    int y = xx.first;
    if (y != son[x] && y != fa[x]) dfs2(y, y);
  }
  lst[x] = tot;
}
int sum[4000003];
inline void upd1(int nl, int nr, int l, int r, int i) {
  if (r < nl || nr < l || sum[i] == 2) return;
  if (l <= nl && nr <= r) return (void)(sum[i] = 2);
  int mid = (nl + nr) >> 1;
  upd1(nl, mid, l, r, i << 1), upd1(mid + 1, nr, l, r, (i << 1) + 1),
      sum[i] = 1 + (sum[i << 1] == 2 && sum[(i << 1) + 1] == 2);
  return;
}
inline int query(int nl, int nr, int l, int r, int i) {
  if (r < nl || nr < l) return 0;
  if (!sum[i]) return 0;
  if (sum[i] == 2) return 1;
  if (l <= nl && nr <= r) return sum[i];
  int mid = (nl + nr) >> 1;
  return query(nl, mid, l, r, i << 1) + query(mid + 1, nr, l, r, (i << 1) + 1);
}
signed main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; ++i) Fa[i] = i;
  for (int i = 1; i <= m; ++i) u[i] = read(), v[i] = read(), w[i] = read();
  for (int i = 1; i <= m; ++i) {
    int A = find(u[i]), B = find(v[i]);
    if (A != B) {
      e[u[i]].push_back(make_pair(v[i], w[i])),
          e[v[i]].push_back(make_pair(u[i], w[i]));
      Fa[A] = B;
      ans[i] = 2;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) dfs1(i), dfs2(i, i);
  for (int i = 1; i <= m; ++i)
    if (!ans[i]) {
      int x = u[i], y = v[i];
      bool flg = 1;
      if (!(V[x] ^ V[y] ^ w[i])) continue;
      ans[i] = -1;
      while (top[x] != top[y]) {
        if (dep[top[y]] > dep[top[x]]) swap(x, y);
        if (query(1, n, dfn[top[x]], dfn[x], 1)) {
          flg = 0;
          break;
        }
        x = fa[top[x]];
      }
      if (flg)
        if (x == y ||
            query(1, n, min(dfn[x], dfn[y]) + 1, max(dfn[x], dfn[y]), 1) == 0) {
          int x = u[i], y = v[i];
          while (top[x] != top[y]) {
            if (dep[top[y]] > dep[top[x]]) swap(x, y);
            upd1(1, n, dfn[top[x]], dfn[x], 1);
            assert(query(1, n, dfn[top[x]], dfn[x], 1) > 0);
            x = fa[top[x]];
          }
          if (x != y)
            upd1(1, n, min(dfn[x], dfn[y]) + 1, max(dfn[x], dfn[y]), 1);
          ans[i] = 1;
        }
    }
  for (int i = 1; i <= m; ++i)
    if (ans[i] > 0)
      puts("YES");
    else
      puts("NO");
  return 0;
}
