#C10536. Largest Friends Group

    ID: 39752 Type: Default 1000ms 256MiB

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 and m where n (1 ≤ n ≤ 10^5) is the number of people, and m (0 ≤ m ≤ 10^5) is the number of friendships.
  • The next m lines each contain two integers a and b (1 ≤ a, b ≤ n) representing a bidirectional friendship between person a and person b.

outputFormat

For each test case, output in a single line the size of the largest friend group.

## sample
2
5 3
1 2
1 3
4 5
4 2
1 2
3 4
3

2

</p>