You are given a connected simple undirected graph with vertices and edges. The vertices are numbered from to , and the initial color of vertex is a positive integer . A simple graph has neither self-loops nor multiple edges.
You may perform the following operation at most once.
After the operation, delete every edge whose endpoints have different colors. No vertices are deleted.
Find the maximum possible number of vertices in the largest connected component of the remaining graph. A component consisting of a single vertex has size .
For example, suppose the edges are and the initial colors are . By choosing edge and assigning color to both endpoints, all vertices have the same color. This gives a component of size .
The input is given in the following format.
For each test case, print the maximum possible size of the largest connected component on one line.
The first test case is the example from the statement.
In the second test case, both vertices already belong to the same component without an operation.
In the third, choose edge and change both endpoints to color . Vertices then form one component. Since all initial colors are distinct and only two vertices may be recolored, four vertices cannot end up with the same color.
In the fourth, changing vertices to color gives a component of size .
is the number of test cases. Each test case has the following format.
The first line contains the number of vertices and the number of edges . The second line contains the initial colors. Each of the next lines gives an edge: are the endpoints of the -th edge ().
No additional constraints. |