Skip to content

1053: Journey

题目

题目描述

There are $n$ cities and $n - 1$ roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.

Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.

Let the length of each road be $1$. The journey starts in the city $1$. What is the expected length (expected value of length) of their journey?

一句话题意: 给定 $n$ 个点的树,求到达每个叶子节点的期望,答案四舍五入保留两位小数。

输入格式

The first line contains a single integer $n$ — number of cities.

Then $n - 1$ lines follow. The $i$-th line of these lines contains two integers $u_i$ and $v_i$ ($1 \leq  u_i, v_i \leq  n$) — the cities connected by the $i$-th road.

输出格式

Print a number — the expected length of their journey. The journey starts in the city $1$.

样例输入

样例输入1

text 4 1 2 1 3 2 4

样例输入2

text 5 1 2 1 3 3 4 2 5

样例输出

样例输出1

text 1.50

样例输出2

text 2.00

数据范围

For all $n$, $1\leq n \leq 100000$

It is guaranteed that one can reach any city from any other by the roads.

Oops! 本题目还没有解答!

助教老师们编题的速度,已经超过了解题的速度!

OJ翻了一新,但本解答集还大多用的是2017-2019级,甚至更早的同学们贡献的答案。

如果你已经AC了,可以的话,请您参考添加页面,与大家一起分享你的题解!