#C10536. Largest Friends Group
Largest Friends Group
Largest Friends Group
Given a group of n people and a list of pairs representing bidirectional friendships, two people are in the same friend group if they are directly or indirectly connected. In graph theory terms, each friend group corresponds to a connected component in an undirected graph.
Your task is to determine the size of the largest friend group.
For example, if n = 5 and the friendships are given as (1,2), (1,3), (4,5)
, then the connected components are {1,2,3} and {4,5} so the largest group size is 3.
Recall that the friend group size is simply the number of nodes in a connected component. In LaTeX, a connected component is defined as a set \(C\) such that for every pair of nodes \(i, j \in C\) there exists a path connecting \(i\) and \(j\).
inputFormat
The first line of input contains an integer t
(1 ≤ t ≤ 100), the number of test cases. Each test case is described as follows:
- The first line contains two integers
n
andm
wheren
(1 ≤ n ≤ 10^5) is the number of people, andm
(0 ≤ m ≤ 10^5) is the number of friendships. - The next
m
lines each contain two integersa
andb
(1 ≤ a, b ≤ n) representing a bidirectional friendship between persona
and personb
.
outputFormat
For each test case, output in a single line the size of the largest friend group.
## sample2
5 3
1 2
1 3
4 5
4 2
1 2
3 4
3
2
</p>