Program time limit: 1 second
Program memory limit: 256 MB
This year, the Community of Pond Members (CPM) has welcomed many new ducks. The community can be represented as an undirected connected tree with $N$ vertices, where each vertex is a duck and each edge is a mentor-apprentice connection.
A duck is considered new if it has exactly one connection. In graph terms, the new ducks are the leaves of the tree.
For any pair of new ducks, consider the simple path between them. Let:
The familiarity value of the pair is $D \times F$.
Keane wants to find the maximum familiarity value over all pairs of new ducks, and the number of pairs that achieve this maximum value.
You should read from standard input.
Additionally:
You should write to standard output.
8
1 2
1 3
1 4
2 5
2 6
3 7
3 8
6 6
If we pick the pair $(5, 8)$, the path is $5 \rightarrow 2 \rightarrow 1 \rightarrow 3 \rightarrow 8$. Its length is $4$. Every other duck has distance at most $1$ from this path, so the familiarity value is $4 \times 1 = 4$.
If we pick the pair $(4, 8)$, the path is $4 \rightarrow 1 \rightarrow 3 \rightarrow 8$. Its length is $3$. Every other duck has distance at most $2$ from this path, so the familiarity value is $3 \times 2 = 6$.
If we pick the pair $(5, 6)$, the path is $5 \rightarrow 2 \rightarrow 6$. Its length is $2$. Every other duck has distance at most $3$ from this path, so the familiarity value is $2 \times 3 = 6$.
Among all pairs of new ducks in the sample, six pairs have familiarity value $6$, which is the maximum possible value.
Your program will be tested on the sample case and several hidden cases. If it produces the correct output for all test cases, it will be considered correct. Recall that your final score for this problem is the score of your highest-scoring submission.
The contest ended at 8:16 p.m. AEST on Thursday 2nd July. All submissions will be unofficial .