#C11546. Network Connectivity Checker

    ID: 40874 Type: Default 1000ms 256MiB

Network Connectivity Checker

Network Connectivity Checker

You are given a network of servers connected by direct links. The network is represented as an undirected graph with N nodes and M edges. Your task is to determine whether the network is fully connected: that is, there exists a path between every pair of servers.

The input starts with an integer T denoting the number of test cases. For each test case, the first line contains two integers, N and M, representing the number of servers and the number of connections respectively. The following M lines each contain two integers u and v which indicate a bidirectional connection between server u and server v.

Your output must be a single line for each test case, printing CONNECTED if the entire network is connected, or DISCONNECTED otherwise.

Note: In cases where N = 1, the network is trivially connected.

The connectivity condition can be mathematically stated as: For a given graph G(V,E) with |V| = N, the network is fully connected if and only if for every pair of nodes u, v in V, there exists a path from u to v.

inputFormat

The first line contains an integer T (1 ≤ T), representing the number of test cases. Each test case is described as follows:

  • The first line of each test case contains two integers N and M, where N is the number of servers and M is the number of connections.
  • The next M lines each contain two integers u and v (1 ≤ u, v ≤ N), indicating a connection between server u and server v.

All input is provided via standard input (stdin).

outputFormat

For each test case, output a single line containing either CONNECTED or DISCONNECTED on standard output (stdout), indicating whether the network is fully connected.

## sample
2
5 4
1 2
2 3
3 4
4 5
3 1
1 2
CONNECTED

DISCONNECTED

</p>