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.