Institute
시간 제한1초메모리 제한2048 MB
패스가 필요한 간선과 필요 없는 간선이 섞인 방향 그래프에서, 정점 1에서 출발해 어떤 정점에 패스를 두고 그 정점으로 다시 돌아올 수 없게 되는지 판정한다.
문제
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 permanently lose it, and then he will not be able to attend classes.
The campus of Tikhon's institute is a directed graph. Some of the edges of this graph 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.
입력
The first line contains two integers and (): the number of vertices and edges in the graph, respectively.
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.
출력
Print a line with a single word (case-insensitive): "Yes" if Tikhon can permanently lose his pass, or "No" otherwise.
힌트
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 .