#P10632. Normal
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 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 . If is the centroid of the tree, then the time complexity is .
WJMZBMR decides to choose a node in uniformly at random as . Sevenkplus tells him that the worst-case complexity of doing this is , 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 , the size of the tree. The next lines each contain two integers , meaning there is an edge between and .
The nodes of the tree are numbered starting from .
Output Format
Output one line with a floating-point number, the answer rounded to digits after the decimal point.
3
0 1
1 2
5.6667
Hint
For all testdata, it is guaranteed that .
Translated by ChatGPT 5