#K66307. Network Security Check
Network Security Check
Network Security Check
This problem tests your ability to determine if a given network of computers can be secured. A network is secure if and only if all computers are connected, i.e., for any two computers there exists a path between them. In mathematical terms, for a network with n computers, it is secure if it contains a spanning tree with exactly $n-1$ edges. Note that a network with a single computer is always considered secure.
You are given multiple test cases. For each test case, decide whether the network is secure. Output YES
if the network is secure, and NO
otherwise.
inputFormat
The first line contains an integer t representing the number of test cases. For each test case, the first line contains two integers n and m where n is the number of computers and m is the number of connections. Each of the next m lines contains two integers u and v representing an undirected connection between computer u and computer v.
outputFormat
For each test case, print a single line containing YES
if the network is secure (fully connected), or NO
if it is not.
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
YES
NO
</p>