QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 2048 MB

#22875. 兩個朋友圈

Statistics

JAG 動物園養咗 $N$ 隻馬騮。呢啲馬騮由 $1$ 到 $N$ 編號。

動物園嘅工作人員調查咗馬騮之間嘅關係。對於 $M$ 對馬騮入面嘅每一對,佢哋都已經確定呢兩隻馬騮係咪鍾意對方。根據呢啲資料,你決定將呢 $N$ 隻馬騮分落兩個非空嘅籠入面,等佢哋可以盡量和平噉生活。對於呢啲馬騮對入面嘅每一對,都必須滿足以下條件:

  • 互相鍾意嘅兩隻馬騮必須放喺同一個籠入面。
  • 唔鍾意對方嘅兩隻馬騮必須放喺唔同嘅籠入面。

請判斷係咪可以照呢個方式將啲馬騮分開。

輸入格式

輸入包含單一測試用例,格式如下。

$$ \begin{aligned} &N\ M \\ &a_1\ b_1\ c_1 \\ &a_2\ b_2\ c_2 \\ &\vdots \\ &a_M\ b_M\ c_M \end{aligned} $$

第一行包含兩個整數 $N$ 同 $M$($2 \le N \le 10^5$,$1 \le M \le 10^5$),分別代表馬騮嘅數量同埋馬騮對嘅數量。

接落嚟嘅 $M$ 行,每行包含兩個整數 $a_i$ 同 $b_i$($1 \le a_i, b_i \le N$)以及一個字符 $c_i$,其中 $c_i$ 係 o 或者 x。如果 $c_i$ 係 o,代表馬騮 $a_i$ 同 $b_i$ 互相鍾意。如果 $c_i$ 係 x,代表佢哋唔鍾意對方。保證 $a_i \ne b_i$,而且唔會有任何一對馬騮出現超過一次。

輸出格式

如果可以將啲馬騮分落兩個非空嘅籠入面,輸出 Yes;否則,輸出 No。

範例

輸入格式 1

5 8
2 3 x
2 5 x
1 3 x
3 4 o
1 5 x
4 5 o
3 5 o
1 4 x

輸出格式 1

Yes

輸入格式 2

2 1
1 2 o

輸出格式 2

No

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.