#Lutece1049. Common connected component
Common connected component
Migrated from Lutece 1049 Common connected component
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Alice is given two undirected graphs, both with vertices. For convenience, the vertices are labeled from to . Now Alice is asked to find a subset of vertices, which form a connected component in both two graphs. Alice is wondering the largest size of such subset.
As is known to everyone of you, Bob loves Alice very much. Could you tell Bob the answer to help Bob leave a good impression on Alice.
Input
The first line contains one single integer , indicating the number of vertices in both graphs.
The second line contains one single integer , indicating the number of edges in the first graph.
Each of the following lines contains two integers and , which denotes an edge between and in the first graph.
The following line contains one single integer , indicating the number of edges in the second graph.
Each of the following lines contains two integers and , which denotes an edge between and in the second graph.
It is guaranteed that
Output
Print the size of the largest common connected component in one line.
Samples
3
1
1 2
1
2 3
1
Resources
The 13th UESTC Programming Contest Final