#K60602. Space Stations Connectivity

    ID: 31123 Type: Default 1000ms 256MiB

Space Stations Connectivity

Space Stations Connectivity

You are given a series of test cases. In each test case, you are provided with \(N\) space stations and \(M\) tunnels connecting pairs of stations. Your task is to determine whether all stations are connected, i.e., there is a path between any two stations.

Input Format: The first number is an integer \(T\) representing the number of test cases. For each test case, the first line contains two integers \(N\) and \(M\), denoting the number of space stations and the number of tunnels respectively. This is followed by \(M\) lines, each containing two integers \(u\) and \(v\) indicating that there is a tunnel connecting station \(u\) and station \(v\).

Connectivity: A graph is said to be connected if every station is reachable from any other station. Use a Depth First Search (DFS) or similar method to check connectivity.

inputFormat

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

T
N M
u1 v1
u2 v2
... (M lines)
[Repeat the above test case T times]

Where:

  • T: Number of test cases.
  • N: Number of space stations (nodes) in the test case.
  • M: Number of tunnels (edges) in the test case.
  • u, v: Zero-indexed station numbers indicating a tunnel connection.

outputFormat

For each test case, output a single line with the word "CONNECTED" if all stations are interconnected, or "DISCONNECTED" otherwise. The results must be printed to standard output (stdout).

## sample
1
4 3
0 1
1 2
2 3
CONNECTED

</p>