#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, pd = 0;
  while (ch < '0' || ch > '9') pd ^= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return pd ? -x : x;
}
const int maxn = 300005;
int n, m;
struct Edge {
  int u, v, w, bj;
} d[maxn * 2];
int Fa[maxn];
int ff(int x) { return Fa[x] == x ? x : Fa[x] = ff(Fa[x]); }
int e, bg[maxn], to[maxn << 1], nx[maxn << 1], w[maxn << 1];
void link(int u, int v, int _w) {
  to[++e] = v, nx[e] = bg[u], w[e] = _w, bg[u] = e;
}
int val[maxn], fa[maxn], sz[maxn], son[maxn], dep[maxn], id[maxn], rk[maxn],
    top[maxn];
void dfs1(int u) {
  sz[u] = 1, dep[u] = dep[fa[u]] + 1;
  for (int i = bg[u]; i; i = nx[i]) {
    int v = to[i];
    if (v == u[fa]) continue;
    v[fa] = u, v[val] = w[i], dfs1(v);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
int tot;
void dfs2(int u, int t) {
  top[u] = t, rk[id[u] = ++tot] = u;
  if (son[u])
    dfs2(son[u], t);
  else
    return;
  for (int i = bg[u]; i; i = nx[i])
    if (to[i] != u[fa] && to[i] != son[u]) dfs2(to[i], to[i]);
}
bool yh[maxn << 2], fg[maxn << 2];
bool tag[maxn << 2];
void pushdown(int o) {
  (o << 1)[fg] = (o << 1 | 1)[fg] = 1;
  (o << 1)[tag] = (o << 1 | 1)[tag] = 1;
  o[tag] = 0;
}
void build(int o, int l, int r) {
  if (l == r) {
    o[yh] = val[rk[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid), build((o << 1 | 1), mid + 1, r);
  o[yh] = (o << 1)[yh] ^ (o << 1 | 1)[yh];
}
void cover(int o, int l, int r, int L, int R) {
  o[fg] = 1;
  if (L <= l && r <= R) {
    o[tag] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) cover((o << 1), l, mid, L, R);
  if (R > mid) cover((o << 1 | 1), mid + 1, r, L, R);
}
bool query(int o, int l, int r, int L, int R) {
  if (L <= l && r <= R) return o[yh];
  int mid = (l + r) >> 1;
  if (o[tag]) pushdown(o);
  if (R <= mid) return query((o << 1), l, mid, L, R);
  if (L > mid) return query((o << 1 | 1), mid + 1, r, L, R);
  return query((o << 1), l, mid, L, R) ^ query((o << 1 | 1), mid + 1, r, L, R);
}
bool check(int o, int l, int r, int L, int R) {
  if (L <= l && r <= R) return o[fg];
  int mid = (l + r) >> 1;
  if (o[tag]) {
    pushdown(o);
    return 1;
  }
  if (R <= mid) return check((o << 1), l, mid, L, R);
  if (L > mid) return check((o << 1 | 1), mid + 1, r, L, R);
  return check((o << 1), l, mid, L, R) || check((o << 1 | 1), mid + 1, r, L, R);
}
int getlca(int x, int y) {
  while (x[top] != y[top])
    if (x[top][dep] > y[top][dep])
      x = x[top][fa];
    else
      y = y[top][fa];
  return x[dep] < y[dep] ? x : y;
}
bool qrange(int x, int y) {
  bool res = 0;
  while (x[top] != y[top]) {
    res ^= query(1, 1, n, id[x[top]], id[x]);
    x = x[top][fa];
  }
  if (x != y) res ^= query(1, 1, n, id[y] + 1, id[x]);
  return res;
}
bool check(int x, int y) {
  bool ok = 0;
  while (x[top] != y[top]) {
    ok |= check(1, 1, n, id[x[top]], id[x]);
    x = x[top][fa];
  }
  if (x != y) ok |= check(1, 1, n, id[y] + 1, id[x]);
  return ok ^ 1;
}
void xrange(int x, int y) {
  while (x[top] != y[top]) {
    cover(1, 1, n, id[x[top]], id[x]);
    x = x[top][fa];
  }
  if (x != y) cover(1, 1, n, id[y] + 1, id[x]);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) Fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    int fx = ff(x), fy = ff(y);
    if (fx != fy) Fa[fx] = fy, link(x, y, z), link(y, x, z), d[i].bj = 1;
    d[i].u = x, d[i].v = y, d[i].w = z;
  }
  for (int i = 1; i <= n; i++)
    if (Fa[i] == i) dfs1(i), dfs2(i, i);
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    if (d[i].bj) {
      puts("YES");
      continue;
    }
    int lca = getlca(d[i].u, d[i].v);
    if (qrange(d[i].u, lca) ^ qrange(d[i].v, lca) ^ d[i].w) {
      if (check(d[i].u, lca) && check(d[i].v, lca)) {
        puts("YES");
        xrange(d[i].u, lca), xrange(d[i].v, lca);
      } else
        puts("NO");
    } else
      puts("NO");
  }
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

You have an undirected graph consisting of n vertices with weighted edges.

A simple cycle is a cycle of the graph without repeated vertices. Let the weight of the cycle be the [XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of edges it consists of.

Let's say the graph is good if all its simple cycles have weight 1. A graph is bad if it's not good.

Initially, the graph is empty. Then q queries follow. Each query has the next type: 

  * u v x — add edge between vertices u and v of weight x if it doesn't make the graph bad. 



For each query print, was the edge added or not.

Input

The first line contains two integers n and q (3 ≤ n ≤ 3 ⋅ 10^5; 1 ≤ q ≤ 5 ⋅ 10^5) — the number of vertices and queries.

Next q lines contain queries — one per line. Each query contains three integers u, v and x (1 ≤ u, v ≤ n; u ≠ v; 0 ≤ x ≤ 1) — the vertices of the edge and its weight.

It's guaranteed that there are no multiple edges in the input.

Output

For each query, print YES if the edge was added to the graph, or NO otherwise (both case-insensitive).

Example

Input


9 12
6 1 0
1 3 1
3 6 0
6 2 0
6 4 1
3 4 1
2 4 0
2 5 0
4 5 0
7 8 1
8 9 1
9 7 0


Output


YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, pd = 0;
  while (ch < '0' || ch > '9') pd ^= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return pd ? -x : x;
}
const int maxn = 300005;
int n, m;
struct Edge {
  int u, v, w, bj;
} d[maxn * 2];
int Fa[maxn];
int ff(int x) { return Fa[x] == x ? x : Fa[x] = ff(Fa[x]); }
int e, bg[maxn], to[maxn << 1], nx[maxn << 1], w[maxn << 1];
void link(int u, int v, int _w) {
  to[++e] = v, nx[e] = bg[u], w[e] = _w, bg[u] = e;
}
int val[maxn], fa[maxn], sz[maxn], son[maxn], dep[maxn], id[maxn], rk[maxn],
    top[maxn];
void dfs1(int u) {
  sz[u] = 1, dep[u] = dep[fa[u]] + 1;
  for (int i = bg[u]; i; i = nx[i]) {
    int v = to[i];
    if (v == u[fa]) continue;
    v[fa] = u, v[val] = w[i], dfs1(v);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
int tot;
void dfs2(int u, int t) {
  top[u] = t, rk[id[u] = ++tot] = u;
  if (son[u])
    dfs2(son[u], t);
  else
    return;
  for (int i = bg[u]; i; i = nx[i])
    if (to[i] != u[fa] && to[i] != son[u]) dfs2(to[i], to[i]);
}
bool yh[maxn << 2], fg[maxn << 2];
bool tag[maxn << 2];
void pushdown(int o) {
  (o << 1)[fg] = (o << 1 | 1)[fg] = 1;
  (o << 1)[tag] = (o << 1 | 1)[tag] = 1;
  o[tag] = 0;
}
void build(int o, int l, int r) {
  if (l == r) {
    o[yh] = val[rk[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid), build((o << 1 | 1), mid + 1, r);
  o[yh] = (o << 1)[yh] ^ (o << 1 | 1)[yh];
}
void cover(int o, int l, int r, int L, int R) {
  o[fg] = 1;
  if (L <= l && r <= R) {
    o[tag] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) cover((o << 1), l, mid, L, R);
  if (R > mid) cover((o << 1 | 1), mid + 1, r, L, R);
}
bool query(int o, int l, int r, int L, int R) {
  if (L <= l && r <= R) return o[yh];
  int mid = (l + r) >> 1;
  if (o[tag]) pushdown(o);
  if (R <= mid) return query((o << 1), l, mid, L, R);
  if (L > mid) return query((o << 1 | 1), mid + 1, r, L, R);
  return query((o << 1), l, mid, L, R) ^ query((o << 1 | 1), mid + 1, r, L, R);
}
bool check(int o, int l, int r, int L, int R) {
  if (L <= l && r <= R) return o[fg];
  int mid = (l + r) >> 1;
  if (o[tag]) {
    pushdown(o);
    return 1;
  }
  if (R <= mid) return check((o << 1), l, mid, L, R);
  if (L > mid) return check((o << 1 | 1), mid + 1, r, L, R);
  return check((o << 1), l, mid, L, R) || check((o << 1 | 1), mid + 1, r, L, R);
}
int getlca(int x, int y) {
  while (x[top] != y[top])
    if (x[top][dep] > y[top][dep])
      x = x[top][fa];
    else
      y = y[top][fa];
  return x[dep] < y[dep] ? x : y;
}
bool qrange(int x, int y) {
  bool res = 0;
  while (x[top] != y[top]) {
    res ^= query(1, 1, n, id[x[top]], id[x]);
    x = x[top][fa];
  }
  if (x != y) res ^= query(1, 1, n, id[y] + 1, id[x]);
  return res;
}
bool check(int x, int y) {
  bool ok = 0;
  while (x[top] != y[top]) {
    ok |= check(1, 1, n, id[x[top]], id[x]);
    x = x[top][fa];
  }
  if (x != y) ok |= check(1, 1, n, id[y] + 1, id[x]);
  return ok ^ 1;
}
void xrange(int x, int y) {
  while (x[top] != y[top]) {
    cover(1, 1, n, id[x[top]], id[x]);
    x = x[top][fa];
  }
  if (x != y) cover(1, 1, n, id[y] + 1, id[x]);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) Fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    int fx = ff(x), fy = ff(y);
    if (fx != fy) Fa[fx] = fy, link(x, y, z), link(y, x, z), d[i].bj = 1;
    d[i].u = x, d[i].v = y, d[i].w = z;
  }
  for (int i = 1; i <= n; i++)
    if (Fa[i] == i) dfs1(i), dfs2(i, i);
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    if (d[i].bj) {
      puts("YES");
      continue;
    }
    int lca = getlca(d[i].u, d[i].v);
    if (qrange(d[i].u, lca) ^ qrange(d[i].v, lca) ^ d[i].w) {
      if (check(d[i].u, lca) && check(d[i].v, lca)) {
        puts("YES");
        xrange(d[i].u, lca), xrange(d[i].v, lca);
      } else
        puts("NO");
    } else
      puts("NO");
  }
  return 0;
}

```