K. Roads of the Goose
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The dense, whispering woods of the Unknown stretched endlessly before the three. After a particularly perplexing encounter with a musical grumpkin, they found themselves utterly lost. "If only Adham were here," sighed Omar, staring at a tangle of gnarled roots that looked suspiciously like a forgotten road. "He always knows the shortest path."

Just then, a peculiar figure emerged from the shadows – Adham, perched precariously on the back of a majestic, shimmering goose named Halzoom! Halzoom, it turns out, wasn't just any goose; she possessed an innate, almost magical, understanding of the forest's pathways.

Adham, ever the strategist, explained their predicament. The forest, he revealed, was a vast network of $$$N$$$ quaint, peculiar towns, connected by $$$M$$$ winding roads. Each road $$$i$$$ connected two towns, $$$u_i$$$ and $$$v_i$$$, and took a specific number of days, $$$w_i$$$, to traverse. Halzoom's magic wasn't about changing the speed of roads, but about finding the optimal set of paths.

However, there was a catch. Halzoom's magic only worked if they could choose exactly $$$N-1$$$ roads from the existing $$$M$$$ roads to form a specific type of travel network. This chosen set of $$$N-1$$$ roads, which Adham calls a "Halzoom Highway", must satisfy two crucial conditions:

  • The chosen roads must form a tree on the $$$N$$$ towns. This means all towns must be connected, and there should be no cycles.
  • For every pair of towns $$$u,v$$$, the shortest-travel-time between them on the "Halzoom Highway" (using the original $$$w_i$$$ days for the selected roads) must be exactly equal to the shortest-travel-time between them in the original forest (using all $$$M$$$ roads and their original $$$w_i$$$ days).

Adham, with a glint in his eye, turned to his friends. "Can you help me figure this out? We need to know if it's even possible to construct such a 'Halzoom Highway'!"

Input

The first line contains two integers $$$N$$$ , $$$M$$$ ($$$1 \le N \le 2 \cdot{10^5}, N - 1 \le M \le \min(2 \cdot{10^5} , \ \frac{n\cdot(n - 1)}{2})$$$).

Then $$$M$$$ lines follow. The $$$i_{th}$$$ line contains 3 integers $$$u_i$$$ , $$$v_i$$$ $$$(1 \leq u_i , v_i \leq n)$$$ and $$$w_i$$$ $$$(1 \leq w_i \leq 10^9)$$$.

Output

Print "YES" if there exists a tree that meets the above conditions , otherwise print "NO".

Examples
Input
4 4
1 2 1
3 4 11
1 3 4
2 4 3
Output
YES
Input
4 4
1 2 1
3 4 2
1 3 4
2 4 3
Output
NO