#K55167. Fully Connected Cities

    ID: 29916 Type: Default 1000ms 256MiB

Fully Connected Cities

Fully Connected Cities

You are given a network of cities connected by bidirectional roads. The task is to determine whether the entire network is fully connected, meaning every city can be reached from every other city.

Details:

  • The cities are enumerated from 1 to N.
  • Each test case starts with two integers: the number of cities N and the number of roads M.
  • Then, M lines follow, each containing two integers representing a road connecting two cities.

If the network is fully connected, output Fully Connected. Otherwise, output Not Fully Connected.

The Union-Find (Disjoint Set Union) algorithm is an efficient way to solve this problem. In this problem, you may need to use the union by rank or path compression techniques to optimize the algorithm. The mathematical condition for connectivity can be expressed as:

[ \forall i \in {1,2,\dots,N}, \ \text{find}(i) = \text{find}(1) ]

where find(i) returns the representative of the set containing city i.

inputFormat

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

  • The first line of each test case contains two space-separated integers N (number of cities) and M (number of roads).
  • The next M lines each contain two integers A and B, indicating that there is a road connecting city A and city B.

Input is read from standard input.

outputFormat

For each test case, output a single line with either Fully Connected if every city is reachable from any other city, or Not Fully Connected otherwise. Output is written to standard output.

## sample
1
1 0
Fully Connected

</p>