The group is welcomed to the nation's capital, Washington D.C.!
The city is home to the greatest collection of museums in the world. One museum, the Smithsonian Museum of Natural History, houses the Hope Diamond, one of the largest diamonds in the world, worth >200 million USD.
To keep the diamond safer, the Smithsonian is considering new floorplans for the museum. A floorplan can be described as a collection of $$$n$$$ rooms connected by $$$m$$$ one-way doors. Each one-way door requires a certain access-level to go through in one direction, and is impossible to go through in the other direction. Each person visiting the museum (visitors and employees) have keycards giving them some constant access-level. If their keycard grants them access level $$$k$$$, they can go through all one way doors requiring $$$ \leq k $$$ access-level. The only entrance/exit to the museum is at room $$$1$$$.
We call a museum floorplan foolproof if it is not possible to get stuck in the museum. Specifically, it is possible to get stuck in the museum if there exists an access-level $$$k$$$ such that a person with access-level $$$k$$$ could reach a room in the museum from room 1 for which it is impossible to return to room 1 with access-level $$$k$$$.
Please determine if the given floorplan is foolproof!
The first line contains integers $$$n, m$$$ ($$$1 \leq n, m \leq 10^5$$$) — the number of rooms and the number of hallways.
The $$$i$$$-th of the next $$$m$$$ lines contains three integers, $$$a_i, b_i, c_i$$$ ($$$1 \leq c_i \leq 10^9, 1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) specifying that there is a one-way door leading from room $$$a_i$$$ to room $$$b_i$$$ requiring access-level $$$c_i$$$.
For each pair of rooms $$$x$$$ and $$$y$$$ it is guaranteed that there is at most one one-way door from room $$$x$$$ to room $$$y$$$. Note that there can exist both a door from $$$x$$$ to $$$y$$$ and from $$$y$$$ to $$$x$$$.
Output one word, "YES" or "NO", answering whether the given floorplan is foolproof.
4 51 2 12 4 24 3 22 3 13 1 1
YES
4 51 2 22 3 33 4 44 1 54 2 1
NO