#C9984. Screening Zones

    ID: 54137 Type: Default 1000ms 256MiB

Screening Zones

Screening Zones

In a theater, screening rooms are connected by hallways. Two rooms are considered to be in the same screening zone if there is a way to travel between them directly or indirectly through hallways. In other words, the screening zones correspond to the connected components in an undirected graph where the nodes represent screening rooms (numbered from 0 to S-1) and the edges represent hallways.

Your task is to determine the number of independent screening zones for each test case.

You may use any connectivity algorithm such as union‐find, depth-first search, or breadth-first search. Mathematically, if \(f(i)\) is the representative of room \(i\) after performing union-find, then the number of screening zones is given by:

[ C = \Big|{ i : f(i)=i,;0\le i<S }\Big| ]

Input Example:

2
6 4
0 1
1 2
3 4
4 5
5 0

Output Example:

2
5

inputFormat

The first line of the input contains an integer \(T\), which denotes the number of test cases.

For each test case, the first line contains two integers \(S\) and \(M\), where \(S\) is the number of screening rooms and \(M\) is the number of hallways connecting the rooms.

This is followed by \(M\) lines, each containing two integers \(u\) and \(v\) (separated by a space) indicating there is a bidirectional hallway connecting room \(u\) and room \(v\).

You should read input from stdin.

outputFormat

For each test case, print on a separate line the number of independent screening zones.

You should write output to stdout.

## sample
2
6 4
0 1
1 2
3 4
4 5
5 0
2

5

</p>