CFGym 102059E Electronic Circuit

Description

Joon is taking General Physics II and he is now studying electronic circuits. An electronic circuit consists of several nodes and undirected wires each connecting two distinct nodes. Moreover, a circuit has two distinctive end nodes; a source node and a sink node, where a voltage is applied (usually it is applied by additional wire with a battery connecting the two nodes, but we will neglect it). Each wire has a resistance, and Joon should know how to calculate the composite resistance of a circuit.

By the way, Joon hates complicated things. So he only cares about circuits that can be made by series and parallel compositions, since they are easy to calculate the composite resistance. He calls them 'nice' circuits; formally, a nice circuit can be defined as follows.

  • A circuit with a single wire connecting two end nodes is nice.
  • A circuit obtained by merging the sink node of a nice circuit $$$C_1$$$ and the source node of a nice circuit $$$C_2$$$ into a single node is nice. The source node and the sink node of the obtained circuit are the source node of $$$C_1$$$ and the sink node of $$$C_2$$$, respectively.
  • A circuit obtained by merging the two source nodes of nice circuits $$$C_1$$$ and $$$C_2$$$ into a single node, and merging the two sink nodes of $$$C_1$$$ and $$$C_2$$$ into a single node, is nice. The two end nodes of the obtained circuit are the respective merged end nodes.

He made a circuit with his wires to calculate the composite resistance, but his friend Pringles screwed up his circuit, so now Joon does not know what the end nodes are. To make things worse, he is not even sure whether the circuit is nice or not.

Joon will give you the circuit. He kindly asks you whether the circuit can be nice by appropriately choosing two end nodes. Be careful that there may be multiple wires connecting two nodes.

Input

The first line contains two integers, $$$n$$$ and $$$m$$$ ($$$2\leq n\leq 10^5$$$, $$$1\leq m\leq 3\times 10^5$$$), where $$$n$$$ is the number of nodes and $$$m$$$ is the number of wires. All nodes are numbered from $$$1$$$ to $$$n$$$.

In the following $$$m$$$ lines, each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u,v \leq n$$$ , $$$u \neq v$$$), which represents a wire connecting $$$u$$$ and $$$v$$$. It is guaranteed that every node is attached to at least one wire; otherwise the node does not exist!

Output

Print Yes if the given circuit can be nice, or No otherwise.

Sample Input

Input

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

Output

Yes

Input

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

Output

No

Input

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

Output

Yes

题意:1:一个图如果只有两个点一条边,那么它是好的
2:如果a,b两个图是好的,那么a的终点和b的起点合成一个点后,合成后的图也是好的
3:如果a,b两个图是好的,那么把a,b两个图的起点合成一个点,终点也合成一个点,合成后的图也是好的
现在给你一个图,问这个图是不是好的
思路:重边去重,然后把度数为2的点,例如x-y-z中的y点去掉,把x-z相连,如果产生了重边也去重,重复这个操作,如果最后只剩下两个度数为1的点,那么输出yes,否则输出no

因为第三点的规则,所以重边能去重,因为第二点的规则,所以一条链上度数为2(就是中间的点)的点能去掉


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值