Under construction

Still being built. Things may change

Electronic Circuit

Time limit1sMemory limit1024 MB

Summary
Given an undirected multigraph, decide whether two end nodes can be chosen so that the circuit is built only by series and parallel composition.
Level

Hard8 of 10

Topics
Graph, Hash map, Implementation
Solved
No attempts yet

Problem

Joon is taking General Physics II and is now studying electronic circuits. An electronic circuit consists of several nodes and undirected wires, each connecting two distinct nodes. A circuit has two distinct end nodes: a source node and a sink node, where a voltage is applied. (Usually a battery wire connects the two nodes, but we neglect it.) Each wire has a resistance, and Joon should know how to calculate the composite resistance of a circuit.

Joon dislikes complicated things, so he only cares about circuits that can be made by series and parallel compositions, since their composite resistance is easy to calculate. He calls them nice circuits. Formally, a nice circuit is 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 C1C_1 and the source node of a nice circuit C2C_2 into a single node is nice. The source node and sink node of the result are the source node of C1C_1 and the sink node of C2C_2, respectively.
  • A circuit obtained by merging the two source nodes of nice circuits C1C_1 and C2C_2 into a single node, and merging the two sink nodes of C1C_1 and C2C_2 into a single node, is nice. The two end nodes of the result are the respective merged end nodes.

Figure: Illustration of the definition of nice circuit.

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

Joon will give you the circuit. Determine whether the circuit can be nice by choosing two end nodes appropriately. Note that there may be multiple wires connecting two nodes.

Input

The first line contains two integers nn and mm (2≤n≤100,0002\leq n\leq 100,000, 1≤m≤300,0001\leq m\leq 300,000), where nn is the number of nodes and mm is the number of wires. All nodes are numbered from 11 to nn.

In the following mm lines, each line contains two integers uu and vv (1≤u, v≤n1 \leq u,\ v \leq n, u≠vu \neq v), representing a wire connecting uu and vv. Every node is attached to at least one wire.

Output

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

Examples3

  1. Example 1

    Input
    4 6
    1 2
    2 3
    2 3
    3 4
    1 4
    1 4
    
    Expected output
    Yes
    
  2. Example 2

    Input
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    
    Expected output
    No
    
  3. Example 3

    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
    
    Expected output
    Yes