


The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains an integer ‘N’ representing the size of the ‘vertices’ array.
The second line of each test case contains the ‘N’ space-separated integers representing the element of the ‘VERTICES’ array.
For each test case, print a single line containing a single integer denoting the size of the largest connected component in the graph.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 1000
1 <= VERTICES[i] <= 5000
All ‘VERTICES[i]’ are distinct.
Where ‘T’ is the number of test cases, ‘N’ is the size of the ‘VERTICES’ array, and ‘VERTICES[i]’ is an element in the ‘VERTICES’ array at index ‘i’.
Time limit: 1 sec.
The idea is to use a disjoint set data structure. We will maintain a disjoint set where different numbers are linked together if and only if they have a common factor greater than 1. So, we have to link each element in ‘VERTICES’ with all its factors greater than 1. For this purpose, we will check all the integers ranging from 2 to sqrt(VERTICES[i]). Since if ‘X’ is a factor of ‘P’ then ‘P / X’ is also a factor of 'P’.
After linking, we only have to find which set has the maximum number of elements from the ‘VERTICES’ array. This can be done by maintaining the frequency of the representative element of every set. We will count the elements from ‘VERTICES’ that have the given representative element and output the maximum such frequency.
Algorithm:
Description of ‘DisjointSet’ class
private:
The private part of the ‘DisjointSet’ class will contain two data members:
public:
The private part of the ‘DisjointSet’ class will contain one constructor and two member functions:
Description of ‘DisjointSet’ constructor
The constructor will take one parameter:
DisjointSet(n):
Description of ‘find’ function
The function will take one parameter:
find(x):
Description of ‘Union’ function
The function will take two parameters:
Union(u, v):
COUNT ISLANDS
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers