#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const int N = 800005, Q = 500005;
struct LCT {
  struct Node {
    int s[2], p, v;
    long long sum;
    bool rev;
  } tr[N];
  int stk[N];
  void pushup(int x) {
    tr[x].sum = tr[tr[x].s[0]].sum + tr[x].v + tr[tr[x].s[1]].sum;
  }
  void pushrev(int x) {
    swap(tr[x].s[0], tr[x].s[1]);
    tr[x].rev ^= 1;
  }
  void pushdown(int x) {
    if (tr[x].rev) {
      pushrev(tr[x].s[0]), pushrev(tr[x].s[1]);
      tr[x].rev = 0;
    }
  }
  bool isroot(int x) { return tr[tr[x].p].s[0] != x && tr[tr[x].p].s[1] != x; }
  void rotate(int x) {
    int y = tr[x].p, z = tr[y].p;
    int k = tr[y].s[1] == x;
    if (!isroot(y)) tr[z].s[tr[z].s[1] == y] = x;
    tr[x].p = z;
    tr[y].s[k] = tr[x].s[k ^ 1], tr[tr[x].s[k ^ 1]].p = y;
    tr[x].s[k ^ 1] = y, tr[y].p = x;
    pushup(y), pushup(x);
  }
  void splay(int x) {
    int top = 0, r = x;
    stk[++top] = r;
    while (!isroot(r)) stk[++top] = r = tr[r].p;
    while (top) pushdown(stk[top--]);
    while (!isroot(x)) {
      int y = tr[x].p, z = tr[y].p;
      if (!isroot(y))
        if ((tr[y].s[1] == x) ^ (tr[z].s[1] == y))
          rotate(x);
        else
          rotate(y);
      rotate(x);
    }
  }
  void access(int x) {
    int z = x;
    for (int y = 0; x; y = x, x = tr[x].p) {
      splay(x);
      tr[x].s[1] = y, pushup(x);
    }
    splay(z);
  }
  void makeroot(int x) {
    access(x);
    pushrev(x);
  }
  int findroot(int x) {
    access(x);
    while (tr[x].s[0]) pushdown(x), x = tr[x].s[0];
    splay(x);
    return x;
  }
  void split(int x, int y) {
    makeroot(x);
    access(y);
  }
  bool is_link(int x, int y) {
    makeroot(x);
    return findroot(y) == x;
  }
  bool is_direct_link(int x, int y) {
    return is_link(x, y) && tr[y].p == x && !tr[y].s[0];
  }
  void link(int x, int y) {
    if (!is_link(x, y)) tr[x].p = y;
  }
  void cut(int x, int y) {
    if (is_direct_link(x, y)) {
      tr[x].s[1] = tr[y].p = 0;
      pushup(x);
    }
  }
  long long query(int x, int y) {
    split(x, y);
    return tr[y].sum;
  }
  void update(int x, long long y) {
    splay(x);
    tr[x].v = y;
    pushup(x);
  }
} lct1, lct2;
struct Offline {
  int u, v, x;
  bool f;
} off[Q];
int stac[N], top;
void dfs(int now) {
  stac[++top] = now;
  if (lct2.tr[now].s[0]) dfs(lct2.tr[now].s[0]);
  if (lct2.tr[now].s[1]) dfs(lct2.tr[now].s[1]);
}
void solve() {
  int n = read(), q = read();
  for (int i = 1; i <= q; i++) {
    int u = read(), v = read(), x = read();
    off[i] = {u, v, x};
    if (lct1.is_link(u, v)) continue;
    off[i].f = 1;
    int mid = i + n;
    lct1.tr[mid].v = x;
    lct1.link(u, mid), lct1.link(mid, v);
    lct2.link(u, mid), lct2.link(mid, v);
  }
  for (int i = 1; i <= q; i++) {
    if (off[i].f) {
      puts("YES");
      continue;
    }
    int u = off[i].u, v = off[i].v, x = off[i].x;
    if (lct2.query(u, v) > 0) {
      puts("NO");
      continue;
    }
    if ((lct1.query(u, v) & 1) ^ x) {
      puts("YES");
      lct2.split(u, v);
      dfs(v);
      while (top) {
        int now = stac[top--];
        if (now <= n) continue;
        lct2.update(now, lct2.tr[now].v + 1);
      }
    } else
      puts("NO");
  }
}
int main() {
  int ttt = 1;
  for (int i = 1; i <= ttt; i++) solve();
  return 0;
}
