#K52752. Largest Connected Component of Rooms
Largest Connected Component of Rooms
Largest Connected Component of Rooms
In this problem, you are given a floor plan represented by rooms and hallways. Each room is considered as a node in an undirected graph, and each hallway represents an edge connecting two rooms. A connected component is a set of rooms where each room is reachable from any other room in the same set.
For each test case, you will be provided with the number of rooms and hallways, followed by the descriptions of the hallways. Your task is to determine the size of the largest connected component among the rooms.
The formula for a connected component is based on the concept of graph theory. Given an undirected graph (G=(V,E)), a connected component is a subset (C \subseteq V) such that for every pair of vertices (u, v \in C), there exists a path in (G) connecting (u) and (v).
inputFormat
The first line contains an integer (T) denoting the number of test cases. For each test case:
- The first line contains two integers (R) and (H), where (R) is the number of rooms and (H) is the number of hallways.
- The next (H) lines each contain two space-separated integers (u) and (v) indicating that there is a hallway connecting room (u) and room (v).
If (H = 0), no hallway information is provided for that test case.
outputFormat
For each test case, output a single integer on a new line representing the size of the largest connected component in that test case.## sample
2
5 4
1 2
2 3
3 4
4 5
4 2
1 2
3 4
5
2
</p>