#K78672. Valid Trail Checker

    ID: 35139 Type: Default 1000ms 256MiB

Valid Trail Checker

Valid Trail Checker

You are given T test cases. For each test case, you are given a graph with N nodes and M bidirectional edges. The nodes are numbered from 1 to N. Your task is to determine whether these points and paths form a valid trail. A valid trail is defined as a connected, acyclic graph, i.e. a tree. In other words, for each test case, output "YES" if the graph is connected and does not contain any cycles; otherwise, output "NO".

Note: A tree with N nodes always has exactly N-1 edges, i.e. ( m = n - 1 ).

inputFormat

The input is read from standard input (stdin) and has the following format:

First line: An integer T, the number of test cases.

For each test case:
    First line: Two integers N and M, representing the number of nodes and the number of edges.
    Next M lines: Each line contains two integers u and v, indicating a bidirectional edge between nodes u and v.

outputFormat

For each test case, output a single line to standard output (stdout) containing either "YES" if the graph forms a valid trail (tree) or "NO" otherwise.## sample

2
4 3
1 2
2 3
3 4
4 3
1 2
2 3
1 3
YES

NO

</p>