码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 2027 Travelling Fee

时间:2014-08-18 10:50:54      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   java   os   io   strong   for   

Description

Samball is going to travel in the coming vacation. Now it‘s time to make a plan. After choosing the destination city, the next step is to determine the travel route. As this poor guy has just experienced a tragic lost of money, he really has limited amount of money to spend. He wants to find the most costless route. Samball has just learned that the travel company will carry out a discount strategy during the vacation: the most expensive flight connecting two cities along the route will be free. This is really a big news.

Now given the source and destination cities, and the costs of all the flights, you are to calculate the minimum cost. It is assumed that the flights Samball selects will not have any cycles and the destination is reachable from the source.


Input

The input contains several test cases, each begins with a line containing names of the source city and the destination city. The next line contains an integer m (<=100), the number of flights, and then m lines follow, each contains names of the source city and the destination city of the flight and the corresponding cost. City names are composed of not more than 10 uppercase letters. Costs are integers between 0 to 10000 inclusively.

Process to the end of file.


Output

For each test case, output the minimum cost in a single line.


Sample Input

HANGZHOU BEIJING
2
HANGZHOU SHANGHAI 100
SHANGHAI BEIJING 200


Sample Output

100

 

题意及分析:

题目的意思不难理解,我就不多说了。思路其实就是绕了一个弯。那就是将最短路径上那条的最长的路权值设为0,然后再求一次起点到终点的最短路。至于最长的路是哪一条枚举所有情况就行了。

AC代码:

 

zoj 2027 Travelling Fee,布布扣,bubuko.com

zoj 2027 Travelling Fee

标签:des   style   http   java   os   io   strong   for   

原文地址:http://blog.csdn.net/is_cp/article/details/38656329

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!