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

建议使用的浏览器:

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

1935:Journey

题目描述
There are n cities in Byteland (numbered from 1 to n), connected by bidirectional roads. The king of Byteland is not very generous, so there are only n-1 roads, but they connect the cities in such a way that it is possible to travel from each city to any other city.
One day, a traveller Byterider arrived in the city number k. He was planning to make a journey starting in the city k and visiting on his way cities m1 , m2 , ..., mj (not necessarily in this order) --the numbers m i are all different and they are also different from k. Byterider -- like every traveller -- has only a limited amount of money, so he would like to visit all the cities that he has planned to visit using the shortest possible path (starting in the city k). A path is one road or a sequence of roads, where every next road begins in the city where the previous one ends. Help Byterider to determine the length of the shortest path for his journey.
输入解释
The first line of the standard input contains two integers n and k separated by a single space (2 <= n <= 50000, 1 <= k <= n), n is the number of cities in Byteland and k is the number of the first city on Byterider's path. Each of the following n-1 lines contains the description of one road in Byteland. Line (i + 1) (for 1 <= i <= n-1) contains three integers ai , bi and di separated by single spaces (1 <= ai ; bi <= n, 1 <= di <= 1000), ai and bi are the cities connected by the road, and di is the length of the road. Line (n + 1) contains one integer j -- the number of cities which Byterider would like to visit (1 <= j <= n-1). The next line contains j different integers m i separated by single spaces -- the numbers of the cities that Byterider would like to visit (1 <= mi <= n, mi != k).
输出解释
The first and only line of the standard output should contain exactly one integer: the length of the shortest path for Byterider's journey.
输入样例
4 2
1 2 1
4 2 2
2 3 3
2
1 3
输出样例
5

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 CEOI 2004 sample task

源链接: POJ-1935

最后修改于 2020-10-29T06:18:21+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 30000