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.
Each input file contains one test case. For each case, the first line contains 2 positive integers , the number of cities, and , the total number of routes between pairs of cities; followed by the name of the starting city. The next 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 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.
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 recommended. 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 recommended route. Then in the next line, you are supposed to print the route in the format
6 7 HZH
3 3 195 97
- temp_cost 是到这个城的已用总cost
- temp_happy 是到这个城的路线总happy
- temp_path 是到这个城的路线，是一个列表
from collections import defaultdict