#LCA0000078. Cây, CÂY! (Tree, TREE!!!)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cây, CÂY! (Tree, TREE!!!)
Tree, TREE!!!
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an undirected tree of vertices and integer . For each vertex used as root, consider all size- subsets of distinct vertices. Let be the number of distinct vertices that can be the LCA of at least one such subset when rooted at . Compute . A vertex is its own ancestor. The same LCA vertex contributes only once for any fixed root.
Input
First line contains , followed by edges .
Output
Print one integer: the sum of numbers of distinct possible LCA vertices over all roots.
Subtasks
General constraints: ; ; các cạnh tạo thành cây; kết quả dùng số nguyên 64 bit.
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Input
5 3
1 2
1 3
1 4
1 5
Output
9
Explanation
With root , only vertex can be the LCA of three selected vertices. Rerooting at a leaf changes the possible LCA vertices. Summing across all five root choices gives .