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

建议使用的浏览器:

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

3672:Caves

题目描述
It is said that the people of Menggol lived in caves. A tribe's caves were connected to each other with paths. The paths were so designed that there was one and only one path to each cave. So the caves and the paths formed a tree. There was a main cave, which connected the world outside. The Menggolian always carved a map of the tribe's caves on the wall of the main cave.

Scientists have just discovered Menggolian's tribe. What a heart-stirring discovery! They are eager to explore it. Since the terrain is very complex and dangerous, they decide to send out a robot.

The robot will be landed into the main cave, where he will begin his adventure. It doesn't have to return to the main cave, because the messages of his exploration will be sent immediately to the scientists while he is on the way.

A robot can only walk x meters before it runs out of energy. So the problem arises: given the map of the tribe's caves and a set of x , how many caves can be explored at most?
输入解释
There are multiple test cases in the input file. Each test case starts with a single number n (0<=n<=500) , which is the number of caves, followed by n - 1 lines describing the map. Each of the n - 1 lines contains three integers separated by blanks: i , j , and d (1<=d<=10000) . It means that the i -th cave's parent cave is the j -th cave and the distance is d meters. A parent cave of cave i is the first cave to enter on the path from i to the main cave. Caves are numbered from 0 to n - 1 . Then there is an integer q (1<=q<=1000) , which is the number of queries, followed by q lines. For one query, there is one integer x (0<=x<=5000000) , the maximum distance that the robot can travel. n = 0 indicates the end of input file.
输出解释
For each test case, output q lines in the format as indicated in the sample output, each line contains one integer, the maximum number of caves the robot is able to visit.
输入样例
3 
1 0 5 
2 0 3 
3 
3 
10 
11 
0
输出样例
Case 1: 
2 
2 
3
来自杭电HDUOJ的附加信息
Recommend lcy

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

源链接: HDU-3672

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

共提交 0

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