Under construction

Still being built. Things may change

Institute

Time limit1sMemory limit2048 MB

Summary
Decide if Tikhon can leave his pass at some vertex reachable from vertex 1, then walk to a vertex he cannot return from without the pass.
Level

Medium6 of 10

Topics
Graph, DFS, BFS
Solved
No attempts yet

Problem

Tikhon passed the entrance exams and now studies at a research institute. However, he is afraid to walk around its campus. He is worried that he may forget his pass somewhere and lose it permanently, and then he will not be able to attend classes.

The campus of Tikhon's institute is a directed graph. Some of the edges can only be traversed with a pass.

To lose the pass permanently, Tikhon would need to start at his dormitory, which is located at the first vertex, then walk along zero or more edges of the campus, then leave his pass in some vertex, continue walking around the campus, and then not be able to return to the vertex where he has left the pass.

Tikhon would like to know if he is worried for no reason: please help him find out if it is possible to permanently lose the pass in the campus.

Input

The first line contains two integers nn and mm (1≤n,m≤3⋅1051 \le n, m \le 3 \cdot 10^5): the number of vertices and edges in the graph.

Each of the following mm lines contains three integers uiu_i, viv_i, tit_i (1≤ui,vi≤n1 \le u_i, v_i \le n; 1≤ti≤21 \le t_i \le 2) describing the directed edges of the graph. Edge ii allows passage from uiu_i to viv_i. If a pass is required to go through edge ii, then ti=1t_i = 1, otherwise ti=2t_i = 2.

The given graph may contain loops and multiple edges between the same vertices.

Output

Print a line with a single word (case-insensitive): "Yes" if Tikhon can permanently lose his pass, or "No" otherwise.

Hint

In the first example, Tikhon can first traverse the edge 1→21 \rightarrow 2 with a pass, then, leaving a pass at vertex 22, traverse the edge 2→32 \rightarrow 3. After that, he will not be able to return to vertex 22.

Examples2

  1. Example 1

    Input
    3 4
    1 2 1
    2 3 2
    3 2 1
    3 1 2
    
    Expected output
    Yes
    
  2. Example 2

    Input
    6 8
    1 2 1
    2 3 2
    3 2 2
    3 4 1
    4 1 2
    1 5 2
    5 4 2
    6 1 2
    
    Expected output
    No