QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17864. 电子电路

统计

Joon 正在修读《普通物理学 II》,他目前正在学习电子电路。一个电子电路由若干个节点和连接两个不同节点的无向导线组成。此外,电路有两个特殊的端节点:源节点和汇节点,在这两个节点之间施加电压(通常是通过连接这两个节点的电池和额外导线来施加,但我们忽略这一点)。每条导线都有一个电阻,Joon 需要知道如何计算电路的等效电阻。

顺便说一句,Joon 讨厌复杂的事情。因此,他只关心可以通过串联和并联组合构成的电路,因为这些电路的等效电阻很容易计算。他称这些电路为“好”电路;正式地,“好”电路可以定义如下:

  • 连接两个端节点的单条导线构成的电路是“好”电路。
  • 将一个“好”电路 $C_1$ 的汇节点与另一个“好”电路 $C_2$ 的源节点合并为一个节点所得到的电路是“好”电路。所得电路的源节点和汇节点分别是 $C_1$ 的源节点和 $C_2$ 的汇节点。
  • 将两个“好”电路 $C_1$ 和 $C_2$ 的两个源节点合并为一个节点,并将 $C_1$ 和 $C_2$ 的两个汇节点合并为一个节点所得到的电路是“好”电路。所得电路的两个端节点分别是合并后的端节点。

他用自己的导线制作了一个电路来计算等效电阻,但他的朋友 Pringles 把他的电路搞乱了,所以现在 Joon 不知道端节点是哪两个。更糟糕的是,他甚至不确定这个电路是不是“好”电路。

Joon 会把这个电路给你。他恳请你帮他判断,是否可以通过适当选择两个端节点,使该电路成为“好”电路。请注意,两个节点之间可能存在多条导线。

输入格式

第一行包含两个整数 $n$ 和 $m$($2 \le n \le 10^5$,$1 \le m \le 3 \times 10^5$),其中 $n$ 是节点数,$m$ 是导线数。所有节点从 $1$ 到 $n$ 编号。

接下来的 $m$ 行中,每行包含两个整数 $u$ 和 $v$($1 \le u, v \le n$,$u \ne v$),表示连接 $u$ 和 $v$ 的一条导线。保证每个节点都至少与一条导线相连;否则该节点不存在!

输出格式

如果给定的电路可以通过选择合适的端节点成为“好”电路,则输出 Yes,否则输出 No

样例

输入样例 1

4 6
1 2
2 3
2 3
3 4
1 4
1 4

输出样例 1

Yes

输入样例 2

4 6
1 2
1 3
1 4
2 3
2 4
3 4

输出样例 2

No

输入样例 3

9 12
1 9
1 4
5 4
6 5
1 5
8 1
3 6
6 8
3 8
2 9
9 7
7 2

输出样例 3

Yes

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.