Independent Set (Max)

시간 제한1초메모리 제한2048 MB

요약
트리에서 서로 인접하지 않은 노드들의 집합을 골라 (노드 수) 곱하기 (모두 연결하는 데 필요한 최소 간선 수)를 최대로 만든다.
난이도

어려움10점 중 8점

유형
트리, 동적 계획법, DFS, 그리디
정답자
아직 제출이 없습니다

문제

You are given a tree of NN nodes (numbered from 11 to NN). The edges are numbered from 11 to N−1N - 1; edge ii connects node U_iU\_i and V_iV\_i.

A non-empty set of nodes is independent if none of the nodes in the set are adjacent to each other. The following illustration provides an example of sets which are independent, and sets which are not. The nodes colored in red are the members of the set.

The score of an independent set can be calculated as the product of:

  • the number of nodes in the set, and
  • the minimum number of edges such that all nodes in the set are still connected.

The following illustration provides an example for calculating the score of an independent set. There are 22 nodes in the set. The minimum number of edges to connect all nodes in the set is 33, as shown by the edges colored in red. The score of this set is 2⋅3=62 \cdot 3 = 6.

Note that the score of an independent set consisting of only 11 node is 00.

Determine the maximum score over all non-empty independent sets within the tree.

입력

The first line consists of an integer NN (2≤N≤100,0002 ≤ N ≤ 100\\, 000).

Each of the next N−1N - 1 lines consists two integers U_iU\_i V_iV\_i (1≤U_i,V_i≤N1 ≤ U\_i , V\_i ≤ N). The input edges form a tree.

출력

Output a single integer representing the maximum score over all non-empty independent sets within the tree.

예제2

  1. 예제 1

    입력
    5
    1 2
    1 3
    3 4
    3 5
    
    예상 출력
    12
    
  2. 예제 2

    입력
    8
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    
    예상 출력
    28