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$ ซึ่งเป็น 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.