1087 All Roads Lead to Rome (30 分)
Indeed 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:
For each test case, we are supposed to find the route with the least cost. If such a route is not unique, the one with the maximum happiness will be recommanded. If such a route is still not unique, then we output the one with the maximum average happiness — it is guaranteed by the judge that such a solution exists and is unique.
Hence in the first line of output, you must print 4 numbers: the number of different routes with the least cost, the cost, the happiness, and the average happiness (take the integer part only) of the recommanded route. Then in the next line, you are supposed to print the route in the format City1->City2->...->ROM
.
Sample Input:
1 | 6 7 HZH |
Sample Output:
1 | 3 3 195 97 |
作者: CHEN, Yue
单位: 浙江大学
时间限制: 200 ms
内存限制: 64 MB
代码长度限制: 16 KB
题目大意
从一个城出发去罗马,途径许多城市。给出各城市间距离以及各城市的快乐值,求去罗马最短的路线。如果最短的路线有多条,则选择路线上快乐值和最大的。如果仍有多条,输出平均快乐值最大的(即途径城市最少的)
分析
类似1030 Travel Plan (30 分) 和1003 Emergency (25 分)。
读入数据,利用map映射城市名与编号。用nodes数组记录第i个结点上的信息。包括路径条数,路径上的城市集合,和总快乐值。然后从起点dijkstra即可。注意路径长度相同时路径数的更新。
代码
1 |
|