#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
const int N = 1e6 + 5;
int n;
namespace LCT {
int tag[N], v[N], siz[N], ch[N][2], fa[N], st[N], cov[N];
void init(int n) {
  for (int i = 1; i <= n; i++) cin >> v[i];
}
inline int get(int x) { return ch[fa[x]][1] == x; }
inline int isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void pushup(int rt) {
  cov[rt] = cov[ch[rt][0]] | cov[ch[rt][1]] | v[rt];
  siz[rt] = siz[ch[rt][0]] + siz[ch[rt][1]] + 1;
}
void pushdown(int rt) {
  if (tag[rt]) {
    tag[ch[rt][0]] ^= 1, tag[ch[rt][1]] ^= 1;
    swap(ch[rt][0], ch[rt][1]);
    tag[rt] = 0;
  }
}
void rotate(int x) {
  int f = fa[x], ff = fa[f], w = get(x), ww = get(f);
  if (!isroot(f)) ch[ff][ww] = x;
  fa[ch[f][w] = ch[x][w ^ 1]] = f;
  fa[ch[x][w ^ 1] = f] = x;
  fa[x] = ff;
  pushup(f), pushup(x);
}
void splay(int x) {
  int top = 0, t = x;
  st[++top] = x;
  while (!isroot(t)) st[++top] = (t = fa[t]);
  while (top) pushdown(st[top--]);
  while (!isroot(x)) {
    if (!isroot(fa[x])) {
      if (get(x) == get(fa[x]))
        rotate(fa[x]);
      else
        rotate(x);
    }
    rotate(x);
  }
  pushup(x);
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) {
    splay(x), ch[x][1] = y, pushup(x);
  }
}
void makeroot(int x) {
  access(x);
  splay(x);
  tag[x] ^= 1;
}
void split(int x, int y) {
  makeroot(x);
  access(y);
  splay(y);
}
int findroot(int x) {
  access(x), splay(x);
  while (ch[x][0]) x = ch[x][0], pushdown(x);
  splay(x);
  return x;
}
void link(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) fa[x] = y;
}
void cut(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) return;
  if (ch[x][1] == y && !ch[y][0]) fa[y] = ch[x][1] = 0;
}
void dfs(int rt) {
  if (rt > n) v[rt] = 1;
  if (ch[rt][0]) dfs(ch[rt][0]);
  if (ch[rt][1]) dfs(ch[rt][1]);
  cov[rt] = cov[ch[rt][0]] | cov[ch[rt][1]] | v[rt];
}
void change(int x, int y) {
  split(x, y);
  dfs(y);
}
int query(int x, int y) {
  split(x, y);
  return cov[y];
}
};  // namespace LCT
int f[N], s[N];
int find(int x) {
  if (x == f[x]) return x;
  int t = f[x];
  f[x] = find(f[x]);
  s[x] ^= s[t];
  return f[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) f[i] = i;
  int tot = n;
  for (int i = 1, u, v, x; i <= q; i++) {
    cin >> u >> v >> x;
    if (find(u) != find(v)) {
      int fu = f[u], fv = f[v];
      s[fu] = s[u] ^ s[v] ^ x;
      f[fu] = fv;
      tot++;
      LCT::link(u, tot);
      LCT::link(v, tot);
      cout << "YES\n";
    } else {
      if ((s[u] ^ s[v] ^ x) == 0 || LCT::query(u, v))
        cout << "NO\n";
      else {
        cout << "YES\n";
        LCT::change(u, v);
      }
    }
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve 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;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
const int N = 1e6 + 5;
int n;
namespace LCT {
int tag[N], v[N], siz[N], ch[N][2], fa[N], st[N], cov[N];
void init(int n) {
  for (int i = 1; i <= n; i++) cin >> v[i];
}
inline int get(int x) { return ch[fa[x]][1] == x; }
inline int isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void pushup(int rt) {
  cov[rt] = cov[ch[rt][0]] | cov[ch[rt][1]] | v[rt];
  siz[rt] = siz[ch[rt][0]] + siz[ch[rt][1]] + 1;
}
void pushdown(int rt) {
  if (tag[rt]) {
    tag[ch[rt][0]] ^= 1, tag[ch[rt][1]] ^= 1;
    swap(ch[rt][0], ch[rt][1]);
    tag[rt] = 0;
  }
}
void rotate(int x) {
  int f = fa[x], ff = fa[f], w = get(x), ww = get(f);
  if (!isroot(f)) ch[ff][ww] = x;
  fa[ch[f][w] = ch[x][w ^ 1]] = f;
  fa[ch[x][w ^ 1] = f] = x;
  fa[x] = ff;
  pushup(f), pushup(x);
}
void splay(int x) {
  int top = 0, t = x;
  st[++top] = x;
  while (!isroot(t)) st[++top] = (t = fa[t]);
  while (top) pushdown(st[top--]);
  while (!isroot(x)) {
    if (!isroot(fa[x])) {
      if (get(x) == get(fa[x]))
        rotate(fa[x]);
      else
        rotate(x);
    }
    rotate(x);
  }
  pushup(x);
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) {
    splay(x), ch[x][1] = y, pushup(x);
  }
}
void makeroot(int x) {
  access(x);
  splay(x);
  tag[x] ^= 1;
}
void split(int x, int y) {
  makeroot(x);
  access(y);
  splay(y);
}
int findroot(int x) {
  access(x), splay(x);
  while (ch[x][0]) x = ch[x][0], pushdown(x);
  splay(x);
  return x;
}
void link(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) fa[x] = y;
}
void cut(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) return;
  if (ch[x][1] == y && !ch[y][0]) fa[y] = ch[x][1] = 0;
}
void dfs(int rt) {
  if (rt > n) v[rt] = 1;
  if (ch[rt][0]) dfs(ch[rt][0]);
  if (ch[rt][1]) dfs(ch[rt][1]);
  cov[rt] = cov[ch[rt][0]] | cov[ch[rt][1]] | v[rt];
}
void change(int x, int y) {
  split(x, y);
  dfs(y);
}
int query(int x, int y) {
  split(x, y);
  return cov[y];
}
};  // namespace LCT
int f[N], s[N];
int find(int x) {
  if (x == f[x]) return x;
  int t = f[x];
  f[x] = find(f[x]);
  s[x] ^= s[t];
  return f[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) f[i] = i;
  int tot = n;
  for (int i = 1, u, v, x; i <= q; i++) {
    cin >> u >> v >> x;
    if (find(u) != find(v)) {
      int fu = f[u], fv = f[v];
      s[fu] = s[u] ^ s[v] ^ x;
      f[fu] = fv;
      tot++;
      LCT::link(u, tot);
      LCT::link(v, tot);
      cout << "YES\n";
    } else {
      if ((s[u] ^ s[v] ^ x) == 0 || LCT::query(u, v))
        cout << "NO\n";
      else {
        cout << "YES\n";
        LCT::change(u, v);
      }
    }
  }
  return 0;
}

```