#C7778. Determine Whether a Graph is a Tree

    ID: 51686 Type: Default 1000ms 256MiB

Determine Whether a Graph is a Tree

Determine Whether a Graph is a Tree

You are given an undirected graph with n vertices and m edges. The task is to determine whether the graph is a tree.

A tree is defined as a connected and acyclic graph. In other words, an undirected graph is a tree if and only if it meets the following conditions:

  • \( m = n - 1 \)
  • The graph is connected

The input consists of the number of vertices and edges followed by an edge list. Print "YES" if the graph is a tree, otherwise print "NO".

inputFormat

The first line contains two integers n and m, representing the number of nodes and edges respectively.

The following m lines each contain two integers u and v, indicating there is an undirected edge between nodes u and v.

outputFormat

Output a single line containing "YES" if the graph is a tree, otherwise output "NO".

## sample
4 3
1 2
2 3
3 4
YES