Divisible Trees

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

요약
트리 T가 주어졌을 때, T를 A의 k개 복사본이 k-1개의 간선으로 이어진 형태로 만들 수 있는 서로 다른 (비라벨) 트리 A의 개수를 센다.
난이도

어려움10점 중 8점

유형
트리, 해시맵, 구현, 조합론
정답자
아직 제출이 없습니다

문제

Let AA and BB be two undirected trees. We define the sum A+BA + B as the set of all undirected trees that can be obtained by connecting the trees AA and BB with a single edge between any node in AA and any node in BB.

Similarly, we define the product of a scalar kk and a tree AA as a set of trees which look like kk copies of AA connected by k−1k - 1 new edges. For example, 1⋅A1 \cdot A is the set consisting of a single tree AA. The set 2⋅A2 \cdot A is just A+AA + A. Now, 3⋅A3 \cdot A is the set of trees each of which is 33 copies of AA with 22 additional edges connecting them into a single tree. And so on.

We say that a tree AA divides a tree BB if there exists a positive integer kk such that BB is included in the set k⋅Ak \cdot A. We observe that, similar to divisibility in the case of natural numbers, any tree is divisible by itself and the "unit" tree: the tree consisting of a single node.

Given a tree TT, the task is to count how many distinct trees divide it.

We say that two trees are distinct if vertices of one tree cannot be relabeled to obtain the other tree.

입력

The first line of the input contains a single integer nn (1≤n≤1051 \leq n \leq 10^5), the number of vertices in the tree.

Each of the next n−1n - 1 lines contains two distinct integers uu and vv (1≤u,v≤n1 \leq u, v \leq n), the ends of an edge in the tree.

출력

Output a single integer, the number of distinct trees that divide TT.

예제1

  1. 예제 1

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