#C11769. Reach Every Park
Reach Every Park
Reach Every Park
You are given a number of test cases. In each test case, there are N parks and M bidirectional roads connecting certain pairs of parks. Your task is to determine whether every park is reachable from every other park. In other words, you need to check if the graph is connected.
The connectivity criterion can be expressed in terms of graph theory: A graph \(G\) is connected if and only if for every pair of vertices there exists a path in \(G\) connecting them.
Input Format: The first line contains an integer \(T\), denoting the number of test cases. For each test case, the first line contains two integers \(N\) and \(M\) separated by a space, where \(N\) is the number of parks and \(M\) is the number of roads. This is followed by \(M\) lines each containing two integers \(u\) and \(v\) indicating that there is a road between park \(u\) and park \(v\).
Output Format: For each test case, print a single line "YES" if every park is reachable from every other park, otherwise print "NO".
Constraints:
- \(1 \leq T \leq 100\)
- \(1 \leq N \leq 10^5\)
- \(0 \leq M \leq 10^5\)
inputFormat
The input is read from standard input (stdin) and is structured as follows:
T N M u1 v1 u2 v2 ... (M lines) ... (repeat for each test case)
Where:
- T is the number of test cases.
- For each test case, N is the number of parks and M is the number of roads.
- Each of the next M lines contains two integers u and v, representing an undirected road between park u and park v.
outputFormat
For each test case, output a single line to the standard output (stdout):
YES
if every park is reachable from every other park, or
NO
otherwise.
## sample3
3 3
1 2
2 3
3 1
4 2
1 2
3 4
5 0
YES
NO
NO
</p>