#P2307. Maze Design Verification

    ID: 15581 Type: Default 1000ms 256MiB

Maze Design Verification

Maze Design Verification

Xiaoxi loves maze games and she has designed her own maze. In her design, all corridors are bidirectional, meaning that if a corridor connects room A and room B, one can travel from A to B and from B to A through that corridor. To increase the challenge, Xiaoxi requires that between any two distinct rooms, there exists exactly one simple path (without retracing steps) connecting them. Given the design plan of the maze represented as an undirected graph, determine whether the design meets Xiaoxi's requirements.

In simpler terms, the maze must be a tree. That is, it should be connected and must not contain any cycles. For example, the first two cases below meet the conditions, but the last one fails because there are two different paths between room $5$ and room $8$.

inputFormat

The first line contains two integers $n$ and $m$, representing the number of rooms and corridors respectively. Each of the following $m$ lines contains two integers $u$ and $v$, indicating that there is a bidirectional corridor connecting room $u$ and room $v$.

outputFormat

Output YES if the maze design meets the requirements, otherwise output NO.

sample

4 3
1 2
2 3
3 4
YES