#abc231d. D - Neighbors

D - Neighbors

Score : 400400 points

问题描述

确定是否存在一种方法,将编号为 11NNNN 个人从左到右排成一行,以满足以下格式中的所有 MM 个条件。

  • 条件格式:人员 AiA_i 和人员 BiB_i 是相邻的。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Determine whether there is a way to line up NN people, numbered 11 to NN, in a row side by side to satisfy all of the MM conditions in the following format.

  • Condition: Person AiA_i and Person BiB_i are adjacent.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 0M1050 \leq M \leq 10^5
  • 1Ai<BiN1\leq A_i < B_i \leq N
  • All pairs (Ai,Bi)(A_i,B_i) are distinct.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

If there is a way to line up people to satisfy the conditions, print Yes; if not, print No.

Sample Input 1

4 2
1 3
2 3

Sample Output 1

Yes

One way to satisfy all the conditions is to line them up in the order 4,1,3,24,1,3,2.

Sample Input 2

4 3
1 4
2 4
3 4

Sample Output 2

No

There is no way to line them up to satisfy all the conditions.

update @ 2024/3/10 10:04:49