#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > e[300005];
int fa[300005], sz[300005], sn[300005], dp[300005], st[300005], ed[300005],
    tp[300005], dis[300005], dft;
void dfs1(int u, int fat) {
  dp[u] = dp[fa[u] = fat] + 1, sz[u] = 1, sn[u] = 0;
  for (auto [v, w] : e[u])
    if (v ^ fat)
      dis[v] = dis[u] ^ w, dfs1(v, u), sz[u] += sz[v],
      sn[u] = (sz[sn[u]] > sz[v]) ? sn[u] : v;
}
void dfs2(int u, int top) {
  tp[u] = top, st[u] = ++dft;
  if (sn[u]) dfs2(sn[u], top);
  for (auto [v, w] : e[u])
    if (v != sn[u] && v != fa[u]) dfs2(v, v);
  ed[u] = dft;
}
int tr[500005];
int n, m, u[500005], v[500005], w[500005], an[300005];
void add(int p) {
  for (; p <= n; p += (p & -p)) tr[p]++;
}
int Q(int l, int r) {
  if (l > r) return 0;
  int res = 0;
  for (; r; r -= (r & -r)) res += tr[r];
  for (l--; l; l -= (l & -l)) res -= tr[l];
  return res;
}
bool chk(int u, int v) {
  for (; tp[u] ^ tp[v]; u = fa[tp[u]]) {
    if (dp[tp[u]] < dp[tp[v]]) swap(u, v);
    if (Q(st[tp[u]], st[u])) return 0;
  }
  if (dp[u] > dp[v]) swap(u, v);
  if (Q(st[u] + 1, st[v])) return 0;
  return 1;
}
int find(int x) { return an[x] == x ? x : an[x] = find(an[x]); }
bool vis[500005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) an[i] = i;
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d%d", u + i, v + i, w + i);
    if ((x = find(u[i])) != (y = find(v[i])))
      an[x] = y, e[u[i]].emplace_back(v[i], w[i]),
      e[v[i]].emplace_back(u[i], w[i]), vis[i] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!st[i]) dfs1(i, 0), dfs2(i, i);
  for (int i = 1; i <= m; i++) {
    if (vis[i])
      puts("YES");
    else if (w[i] ^ dis[u[i]] ^ dis[v[i]] == 0)
      puts("NO");
    else {
      if (chk(u[i], v[i])) {
        puts("YES");
        for (int x = u[i], y = v[i]; x ^ y; add(st[x]), x = fa[x])
          if (dp[x] < dp[y]) swap(x, y);
      } else
        puts("NO");
    }
  }
}
