Check if a Graph Is a Linked List
Given an undirected graph with
v
vertices and e
edges, you are asked to determine if the graph is actually a linked list.![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F40645554-1041-4ada-8c3b-4fc44b806abe%2Fprofound.academy-graphs-linked-list.drawio.png?table=block&id=f406d4f7-d9d9-42e1-a002-26345b9f51c0&cache=v2)
Input
The first line of the input contains two integers
v
(1 ≤ v ≤ 100 000) and e
(1 ≤ e ≤ 100 000).The following
e
lines contain pairs of integers v1
, v2
(1 ≤ v1, v2 ≤ v) which means that the vertex v1
is connected to the vertex v2
and vice versa. Output
The program should print
Yes
if the graph is a linked list and No
otherwise. Examples
Input | Output |
6 5
3 2
2 1
5 6
4 6
1 4 | Yes |
6 4
3 2
2 1
5 6
4 6 | No |
Constraints
Time limit: 4 seconds
Memory limit: 512 MB
Output limit: 1 MB