#P10632. Normal

    ID: 12106 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>图论点分治多项式Special JudgeO2优化期望快速数论变换 NTT

Normal

Problem Description

One day, WJMZBMR learned a magical algorithm: centroid decomposition on a tree.

The core idea of this algorithm is as follows:

time = 0
Solve(Tree a) {
  time += a.size;
  if (a.size == 1) return;
  else {
    select x in a;
    delete a[x];
  }
}
Time cost = 0
Solve(tree a)
  Time cost += size of a
  If there is only 1 node in a
    Exit
  Otherwise
    Choose a node x in a
    Delete node x from a

Then aa becomes several smaller trees, and Solve is called recursively on each subtree.

We notice that the time complexity of this algorithm is closely related to the chosen node xx. If xx is the centroid of the tree, then the time complexity is O(nlogn)O(n \log n).

WJMZBMR decides to choose a node in aa uniformly at random as xx. Sevenkplus tells him that the worst-case complexity of doing this is O(n2)O(n^2), but WJMZBMR does not believe it. So Sevenkplus spent a few minutes writing a program to prove it. You can try it too.

Now you are given a tree. Can you tell WJMZBMR the expected time cost of his algorithm (using the definition in the given Solve function as the standard)?

Input Format

The first line contains an integer nn, the size of the tree. The next n1n-1 lines each contain two integers a,ba, b, meaning there is an edge between aa and bb.

The nodes of the tree are numbered starting from 00.

Output Format

Output one line with a floating-point number, the answer rounded to 44 digits after the decimal point.

3
0 1
1 2
5.6667

Hint

For all testdata, it is guaranteed that 1n300001\leq n\leq 30000.

Translated by ChatGPT 5