Logo
(追記) (追記ここまで)

33378번 - Institute 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB333100.000%

문제

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 $n$ and $m$ (1ドル \le n, m \le 3 \cdot 10^5$): the number of vertices and edges in the graph, respectively.

Each of the following $m$ lines contains three integers $u_i,ドル $v_i,ドル $t_i$ (1ドル \le u_i, v_i \le n$; 1ドル \le t_i \le 2$) describing the directed edges of the graph. Edge $i$ allows passage from $u_i$ to $v_i$. If a pass is required to go through edge $i,ドル then $t_i = 1,ドル otherwise $t_i = 2$.

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.

제한

예제 입력 1

3 4
1 2 1
2 3 2
3 2 1
3 1 2

예제 출력 1

Yes

예제 입력 2

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

예제 출력 2

No

노트

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

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 5: Moscow IPT Yolki-Palki Contest 1 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /