#K5691. Tree Network Validation

    ID: 30303 Type: Default 1000ms 256MiB

Tree Network Validation

Tree Network Validation

You are given a network consisting of N nodes and M links. The network is said to form a tree if it is connected and contains no cycles. In other words, the network is a tree if and only if:

  • The number of links satisfies \(M = N - 1\).
  • The network is connected (i.e. there is a path between any two nodes).

Your task is to determine whether the given network forms a tree. If it does, print YES; otherwise, print NO.

Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line of input contains two integers N and M where N is the number of nodes and M is the number of links.

The following M lines each contains two integers u and v indicating that there is a link between nodes u and v.

You may assume that nodes are numbered from 1 to N.

outputFormat

Print a single line containing YES if the network is a tree, and NO otherwise.

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