問題一覧 > 通常問題

No.1023 Cyclic Tour

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 85
作問者 : chocorusk / テスター : tarattata1
お気に入りにしたユーザー ProblemId : 4008 / 自分の提出
問題文最終更新日: 2020-04-08 14:23:48
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 243 (順位表) の他の問題:

Problem Statement

The country of yuki has $N$ towns numbered $1, 2, \ldots , N$ and $M$ roads numbered $1, 2, \ldots , M$. Road $i$ ($1\leq i\leq M$) connects town $a_i$ and town $b_i$. If $c_i=1$, road $i$ can be traversed in both directions; if $c_i=2$, road $i$ can only be traversed in the direction from town $a_i$ to town $b_i$.

Rusk is planning a sightseeing tour: he starts from some town, visits several towns by traveling along roads, and then returns to the original town. Here, he must visit at least $1$ town other than the starting town, and he wants to avoid visiting the same town twice (except for the final town) and traversing the same road twice. Determine whether this is possible.

Input

$N\ M$
$a_1\ b_1\ c_1$
$a_2\ b_2\ c_2$
$:$
$a_M\ b_M\ c_M$

  • $2\leq N\leq 10^5$
  • $1\leq M\leq 2\times 10^5$
  • $1\leq a_i, b_i\leq N$
  • $1\leq c_i\leq 2$
  • $a_i\neq b_i$
  • $a_i < b_i$ if $c_i=1$
  • $(a_i, b_i, c_i)\neq (a_j, b_j, c_j)$ if $i\neq j$
  • All input values are integers.

Output

Print Yes if it is possible to start from some town and return to the original town without passing through the same town or the same road twice, and No otherwise.

Sample

Sample 1
Input
4 4
1 3 1
2 4 2
2 3 1
4 3 2
Output
Yes

Starting from town $2$, he can travel along roads $2$, $4$, $3$, moving through towns $2\to 4\to 3\to 2$.

Sample 2
Input
4 5
1 2 1
3 1 2
3 2 2
3 4 1
4 2 2
Output
No

Sample 3
Input
2 3
1 2 1
1 2 2
2 1 2
Output
Yes

Sample 4
Input
4 2
1 2 1
3 4 2
Output
No

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。