#P11640. Graph Coloring and Path Constraints
Graph Coloring and Path Constraints
Graph Coloring and Path Constraints
You are given a graph with (n) vertices, where each vertex must be colored either black or white. There are (m) constraints. For the (i)-th constraint, you are given three integers (a_i), (b_i), and (c_i), which means that there must exist a directed path from vertex (a_i) to vertex (b_i) with exact length (c_i). The path is allowed to revisit vertices and edges. Additionally, if the constructed graph has (k) directed edges (each with weight (1)) such that the (i)-th edge goes from vertex (u_i) to vertex (v_i), then the colors of (u_i) and (v_i) must be different.
Determine whether it is possible to construct such a graph.
inputFormat
The first line contains two integers (n) and (m) ((1 \leq n, m \leq 10^5)), representing the number of vertices and the number of constraints, respectively. Each of the following (m) lines contains three integers (a), (b), and (c) (with (c \ge 1)), which represent a constraint. Vertices are numbered from 1 to (n).
outputFormat
Output a single line containing “YES” if such a graph exists, or “NO” otherwise.
sample
3 2
1 2 1
2 3 1
YES