QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 2048 MB

#22875. 2 つの仲良しグループ

Statistics

JAG 動物園では $N$ 匹の猿を飼育している。猿には $1$ から $N$ までの番号が付けられている。

動物園のスタッフは猿たちの人間関係ならぬ猿関係を調査した。$M$ 組の猿のペアそれぞれについて、その 2 匹の猿が互いに好きか嫌いかを調べ上げた。この情報に基づき、あなたは $N$ 匹の猿たちが可能な限り平和に暮らせるよう、2 つの空でない檻に分けることにした。調査された各ペアについて、以下の条件を満たさなければならない:

  • 互いに好きな 2 匹の猿は同じ檻に入れなければならない。
  • 互いに嫌いな 2 匹の猿は異なる檻に入れなければならない。

このように猿たちを分けることが可能かどうかを判定せよ。

入力

入力は以下の形式の単一のテストケースからなる。

$$ \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} $$

1 行目には、猿の数とペアの数をそれぞれ表す 2 つの整数 $N$ と $M$($2 \le N \le 10^5$, $1 \le M \le 10^5$)が与えられる。

続く $M$ 行のそれぞれには、2 つの整数 $a_i$ と $b_i$($1 \le a_i, b_i \le N$)と、o または x のいずれかである文字 $c_i$ が与えられる。$c_i$ が o のとき、猿 $a_i$ と猿 $b_i$ は互いに好きである。$c_i$ が x のとき、互いに嫌いである。$a_i \ne b_i$ であり、同じ猿のペアが複数回現れないことが保証されている。

出力

猿たちを 2 つの空でない檻に分けることが可能であれば 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.