logo AlgoBeat OnlineJudge
登录 注册

#217814. [JAG 2026 Summer Camp #3] Two Friend Groups

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

JAG Zoo keeps monkeys. The monkeys are numbered from to .

The zoo staff have investigated the relationships among the monkeys. For each of pairs of monkeys, they have determined whether the two monkeys like each other or not. Based on this information, you decide to divide the monkeys into two non-empty cages so that they can live as peacefully as possible. For each of these pairs, the following conditions must be satisfied:

  • Two monkeys that like each other must be placed in the same cage.
  • Two monkeys that do not like each other must be placed in different cages.

Determine whether it is possible to divide the monkeys in this way.

输入格式

The input consists of a single test case of the following format.

N M
a_1 b_1 c_1
a_2 b_2 c_2
...
a_M b_M c_M

The first line contains two integers and (, ), representing the number of monkeys and the number of pairs, respectively.

Each of the following lines contains two integers and () and a character , which is either o or x. If is o, monkeys and like each other. If is x, they do not like each other. It is guaranteed that and that no pair of monkeys appears more than once.

输出格式

If it is possible to divide the monkeys into two non-empty cages, print Yes; otherwise, print 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