#C8069. Is It a Tree?

    ID: 52010 Type: Default 1000ms 256MiB

Is It a Tree?

Is It a Tree?

Given an undirected graph with N nodes and M edges, determine whether the graph is a tree. A graph is a tree if and only if it satisfies the following conditions:

  1. The number of edges is exactly $$M = N - 1$$.
  2. The graph is connected.

You are given the number of nodes and edges, followed by M pairs of integers denoting the edges. Output YES if the graph is a tree, otherwise output NO.

inputFormat

The first line contains two integers (N) and (M) representing the number of nodes and edges respectively. Each of the following (M) lines contains two integers (u) and (v), denoting an undirected edge between nodes (u) and (v).

outputFormat

Output a single line containing YES if the graph is a tree, and NO otherwise.## sample

5 4
1 2
2 3
3 4
4 5
YES