#K76232. Largest Connected Component
Largest Connected Component
Largest Connected Component
You are given an undirected graph with \(N\) nodes and \(E\) edges. The task is to determine the size of the largest connected component in the graph. A connected component is a set of nodes where every node is reachable from any other node in the same component.
The graph is provided as follows:
- The first input is an integer \(T\) denoting the number of test cases.
- For each test case, the first line contains two integers \(N\) and \(E\), where \(N\) is the number of nodes and \(E\) is the number of edges in the graph.
- This is followed by \(E\) lines, each containing two integers \(u\) and \(v\) representing an undirected edge between nodes \(u\) and \(v\).
Your task is to output, for each test case, a single integer which is the size of the largest connected component in the graph.
Note: Nodes are numbered from 1 to \(N\).
inputFormat
The input is read from stdin and has the following format:
T N E u1 v1 u2 v2 ... (E lines) ... (Repeat the above for each test case)
Where:
- T is the number of test cases.
- For each test case, the first line contains two integers N (number of nodes) and E (number of edges).
- Each of the next E lines contains two integers u and v representing an undirected edge.
outputFormat
For each test case, output a single integer on a separate line representing the size of the largest connected component in the given graph. The output should be written to stdout.
For example, if the input comprises two test cases, the output might be:
3 2## sample
2
5 3
1 2
2 3
4 5
4 2
1 2
3 4
3
2
</p>