当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5758:Explorer Bo

题目描述
Explorer Bo likes exploring mazes around the world.Now he wants to explore a new maze.

The maze has $N$ rooms connected with $N-1$ roads of length $1$ so that the maze looks like a tree.

Explorer Bo can transfer to a room immediately or walk along a road which is not the one he walked just now.

Because the transfer costs too much, Mr Bo will minimum the transfer using times firstly.

Mr Bo wants to walk along all the roads at least once,but he is lazy and he wants to minimum the total length he walked.

Please help him!

Initial point can be arbitrarily selected
输入解释
The first line of input contains only one integer $T(=20)$, the number of test cases.

For each case, the first line contains $1$ integers, $N( \leq 100000)$ as described before. The following $N-1$ lines describe the path. Each line has $2$ integers, $X,Y(1<=X, Y<=N)$,that there is a road between $X$ and $Y$.
输出解释
Each output should occupy one line.For each case, just output the minimum length to explore all roads.
输入样例
2
3
1 2
2 3
7
1 2
1 3
2 4
2 5
3 6
3 7
输出样例
2
8
来自杭电HDUOJ的附加信息
Author 绍兴一中
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5758

最后修改于 2020-10-25T23:25:25+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 65536/65536K(Java/Others)