Good Graph solution codeforces

Good Graph solution codeforces


You have an undirected graph consisting of nn 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 of weights of edges it consists of.

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

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

  • uu vv xx — add edge between vertices uu and vv of weight xx 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 nn and qq (3n31053≤n≤3⋅1051q51051≤q≤5⋅105) — the number of vertices and queries.

Next qq lines contain queries — one per line. Each query contains three integers uuvv and xx (1u,vn1≤u,v≤nuvu≠v0x10≤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

Copy
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

Copy
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO

 


Leave a Comment