这题和之前一题紧急救援有点像
这里用的变形的dijkstra 每个节点设置一个vector,遇到相同最短路的,就在vector记录来自哪个节点;
这样 dijkstra结束后,就可以从终点往前推出 所有来的最短路径;再对这些路径进行dfs,找到快乐值最大的路径即可;
1087. All Roads Lead to Rome (30)
时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueIndeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers N (2<=N<=200), the number of cities, and K, the total number of routes between pairs of cities; followed by the name of the starting city. The next N-1 lines each gives the name of a city and an integer that represents the happiness one can gain from that city, except the starting city. Then K lines follow, each describes a route between two cities in the format "City1 City2 Cost". Here the name of a city is a string of 3 capital English letters, and the destination is always ROM which represents Rome.
Output Specification: