#C12082. Machine Connectivity Check
Machine Connectivity Check
Machine Connectivity Check
In this problem, you are given a set of machines and a list of bidirectional connections between them. Each connection connects two different machines. Your task is to determine whether all machines are connected together, i.e. whether there exists a path between every pair of machines. Formally, given (n) machines numbered from 1 to (n) and (m) connections, check if the underlying undirected graph is connected. Output CONNECTED
if the graph is connected and DISCONNECTED
otherwise.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer (T) (where (T \geq 1)) representing the number of test cases.
- For each test case, the first line contains two space-separated integers (n) and (m), where (n) is the number of machines and (m) is the number of connections.
- The next (m) lines each contain two integers (u) and (v), indicating that there is a bidirectional connection between machine (u) and machine (v).
outputFormat
For each test case, output a single line containing either CONNECTED
if all machines are connected, or DISCONNECTED
otherwise. The output is printed to standard output (stdout).## sample
3
4 3
1 2
2 3
3 4
3 0
5 3
1 2
2 3
4 5
CONNECTED
DISCONNECTED
DISCONNECTED
</p>