AT_abc401_f [ABC401F] Add One Edge 3

Description

You are given two trees: tree $ 1 $ with $ N_1 $ vertices numbered $ 1 $ to $ N_1 $ , and tree $ 2 $ with $ N_2 $ vertices numbered $ 1 $ to $ N_2 $ . The $ i $ -th edge of tree $ 1 $ connects vertices $ u_{1,i} $ and $ v_{1,i} $ bidirectionally, and the $ i $ -th edge of tree $ 2 $ connects vertices $ u_{2,i} $ and $ v_{2,i} $ bidirectionally. One can add a bidirectional edge between vertex $ i $ of tree $ 1 $ and vertex $ j $ of tree $ 2 $ to obtain a single tree. Let $ f(i,j) $ be the diameter of this tree. Find $ \displaystyle \sum_{i=1}^{N_1}\sum_{j=1}^{N_2} f(i,j) $ . Here, the distance between two vertices of a tree is the minimum number of edges that must be used to move between them, and the diameter of a tree is the maximum distance between two vertices.

Input Format

The input is given from Standard Input in the following format: > $ N_1 $ $ u_{1,1} $ $ v_{1,1} $ $ \vdots $ $ u_{1,N_1-1} $ $ v_{1,N_1-1} $ $ N_2 $ $ u_{2,1} $ $ v_{2,1} $ $ \vdots $ $ u_{2,N_2-1} $ $ v_{2,N_2-1} $

Output Format

Print the answer.

Explanation/Hint

### Sample Explanation 1 For example, one can connect vertex $ 2 $ of tree $ 1 $ and vertex $ 3 $ of tree $ 2 $ to obtain a tree of diameter $ 5 $ . Thus, $ f(2,3) $ is $ 5 $ . The sum of $ f(i,j) $ is $ 39 $ . ### Constraints - $ 1 \le N_1, N_2 \le 2 \times 10^{5} $ - $ 1 \le u_{1,i}, v_{1,i} \le N_1 $ - $ 1 \le u_{2,i}, v_{2,i} \le N_2 $ - Both given graphs are trees. - All input values are integers.