Institute
Time limit1sMemory limit2048 MB
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.
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 and (): the number of vertices and edges in the graph.
Each of the following lines contains three integers , , (; ) describing the directed edges of the graph. Edge allows passage from to . If a pass is required to go through edge , then , otherwise .
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 with a pass, then, leaving a pass at vertex , traverse the edge . After that, he will not be able to return to vertex .