#P3907. Cycle XOR Consistency
Cycle XOR Consistency
Cycle XOR Consistency
Given an undirected graph G with n nodes and m edges. Each edge is described by three integers Ai, Bi and Ci, where Ci is the weight of the edge between nodes Ai and Bi. Determine whether the following property holds:
For every cycle C in the graph, the XOR sum of the weights of its edges is 0, i.e., $$\bigoplus_{e\in C} C_e = 0.$$
Hint: The property holds if and only if one can assign a number xv to each vertex v such that for every edge (u, v) with weight w, the relation below is satisfied:
$$x_u \oplus x_v = w.$$inputFormat
The input is given as follows:
- The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105), representing the number of nodes and the number of edges, respectively.
- Each of the following m lines contains three integers Ai, Bi and Ci (1 ≤ Ai, Bi ≤ n, 0 ≤ Ci ≤ 109), describing an undirected edge between nodes Ai and Bi with weight Ci.
outputFormat
Output a single line containing Yes
if the property holds, or No
otherwise.
sample
3 3
1 2 1
2 3 2
3 1 3
Yes