Problem: This is the easy version of the problem. The differences between the two versions are the constraint on and the time limit. You can make hacks only if both versions of the problem are solved.
You are given a tree with vertices rooted at vertex .
For some permutation of length , let be the number of pairs of vertices such that . Here, denotes the lowest common ancestor of vertices and .
Find the maximum possible value of over all permutations of length .
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Input Format: The first line contains a single integer ().
The second line contains integers () indicating that there is an edge between vertices and .
Output Format: Output the maximum value of .
Note: The tree in the first test:
One possible optimal permutation is with suitable pairs of vertices:
- , since and ,
- , since and ,
- , since and ,
- , since and .
The tree in the third test:
The tree in the fourth test: