Under construction

Still being built. Things may change

Y

Time limit1.5sMemory limit1024 MB

Summary
From a given tree, delete any vertices to leave the largest subtree shaped like a Y: three leaf paths meeting at one center, with no vertex of degree 4 or more.
Level

Hard8 of 10

Topics
Tree, DFS, Dynamic programming, Greedy
Solved
No attempts yet

Problem

A Y-tree is a tree that satisfies all of the following conditions.

  1. No vertex is adjacent to 44 or more vertices.
  2. There is exactly one vertex adjacent to 33 vertices.
  3. There are exactly three vertices adjacent to exactly one vertex.

The size of a Y-tree is the number of vertices that form it.

You are given a tree with NN vertices numbered 11, 22, …, NN, one number per vertex. Write a program that finds the size of the largest Y-tree that can be obtained by deleting zero or more vertices from the given tree.

Input

The first line gives the integer NN, the number of vertices in the tree. (2≤N≤100 0002 \leq N \leq 100\,000)

The next N−1N-1 lines each give two integers uu and vv describing an edge of the tree. This means there is an edge connecting vertex uu and vertex vv. (1≤u,v≤N1 \leq u, v \leq N, u≠vu \neq v)

Every edge of the tree is given exactly once.

Output

On the first line, print the size of the largest Y-tree that can be made from the given tree.

If no Y-tree can be made, print 00.

Examples2

  1. Example 1

    Input
    8
    1 2
    1 3
    2 4
    1 5
    2 6
    2 7
    8 7
    
    Expected output
    6
    
  2. Example 2

    Input
    3
    1 2
    2 3
    
    Expected output
    0