We define a windmill graph as a graph G centered on node c with at least 5 adjacent paths. One of these paths has to have length at least 3 and it is interpreted as the base of the windmill. The remaining paths have length exactly 1 and are interpreted as the sails of the windmill.
For example, the graph given below is a windmill with 8 nodes centered on node 1 with 5 adjacent paths and the base of length 3.
2 3
\ /
5 ---- 1 -----4
|
6
|
7
|
8
For a given tree T with N nodes, the goal is to find the size of its largest subgraph (in terms of the number of nodes) which is a windmill graph and it’s center vertex. If there are many such largest subgraphs, take the one with the smallest center vertex. If no windmill graph is a subgraph of T, then the answer is 1.
Constraints:
\(1 \leq N \leq 10^5\)
Input format:
On the first line, there is a single integer N denoting the number of nodes in the tree T. Then, \(N-1\) lines follow. Each of them contains two space-separated integers u and v and denotes that there is an edge between nodes u and u in the tree.
Output format:
If there is no subgraph of T which is a windmill graph output 1 in a single line. Otherwise, output two space-separated integers \(result\) and c, where \(result\) is the size of the largest windmill subgraph of T and c is the smallest center node among all the largest windmill subgraphs of T.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial