In an unrooted tree, for a given pair $$$(u, v)$$$, delete all edges on the path from $$$u$$$ to $$$v$$$. Find out the max size of the connected components that are created after this deletion. Call this $$$S$$$.
For each $$$S$$$ in $$$[1, N]$$$, determine how many pairs achieve this $$$S$$$.
I created a video discussing how to solve this problem in $$$O(N^3)$$$ and then optimize it to $$$O(N^2)$$$ by rerooting the tree. Practice Problem
Disclaimer : The intended solution of the linked problem is $$$O(N \cdot Log(N))$$$, but solving it even in $$$O(N^2)$$$ is a good exercise.







