XZC Graduation Travel Plan Apare_xzc

XZC Graduation Travel Plan Time limit: 1000ms Memory limit: 256M Face: XZC intends to graduate on a trip to reach i...
AC happy~
XZC Graduation Travel Plan

Time limit: 1000ms
Memory limit: 256M

Face:

XZC intends to graduate on a trip to reach its destination from its place of departure.The map has n cities and m two-way high-speed rail lines.Can you help him find the cheapest and least transit route?He is also a student party, so the first thing to do is to make sure that the high-speed ticket fees from the starting point to the destination (because it is too slow for him to go home for 20 hours, which he has had enough of) and accommodation are minimal.On the basis of the most economical basis, he wants to transfer the least number of times, after all, it is a very troublesome thing, people are not familiar with the life...Clever can you help him?
He has k questions, each of which may have a different starting point and destination.The destination is the city to travel to.So why does it start from a different place?Is that not easy yet?Because he may start after a big meal at school or with his roommates, or in another city after an internship, or he may go home first to pick up the good stuff and start at home, or he may go to the npy home and then travel 23333 together.For each inquiry, he wants you to recommend in detail the cheapest route with the least transit costs.You have a map showing the latest high-speed lines and ticket prices.You're here to help him talk ~

Input format:
  • Multiple sets of inputs (we have multiple sets of inputs in the input file because high-speed ticket prices and routes change dynamically)
  • For each test file, the first line is a positive integer T (T<=5) representing the number of groups of data, followed by T group data
  • The first row of each set of data is two positive integers, N and m, representing the number of cities and the number of existing high-speed rail lines between cities.Where n<=10,000 and m<=100,000.Next there are m lines, with two different strings u,v, and positive integer C (C<=100,000) separated by spaces, each with a length less than 20.There is a high-speed line between the two cities, u and v, with a ticket price of C.
  • Next, there are n lines, each with a string city and a non-negative integer x representing the minimum x (yuan) spent in transit through the city, including taxi fare, accommodation (if needed), and so on.
  • The next line has a positive integer k indicating the number of queries, k<=2000
  • Next there are k lines, two strings per line u,v for origin u and destination v
Output format:
  • Group K input, first output a line "Case #k:" (no quotation marks)
  • Output two empty lines between each set of inputs to enhance readability, and do not output empty lines after the last query of the last set of inputs!
  • For the first query in the same set of inputs, first output a line "query (i):" (no quotation marks, 2 spaces at the beginning of the line), and at the same time output an empty line between the two queries, and no empty line after the last query!
  • Each line of output for each query is indented by four spaces.If the origin or destination is not in n cities, output the relevant prompts, see the example; if both the origin and destination are in n cities on the map, but there is no high-speed rail connection, also output the relevant prompts, see the example.If there is an answer, output the minimum number of routes to spend, satisfy the minimum number of routes to spend, and give a specific route with the least transit.The format is illustrated in an example.
sample input
4 5 4 A B 1000 B C 2000 A C 355000 E D 4164 A 12 B 21 C 12 D 4 E 9 5 A C A D E A A F X Y 6 8 Beijing Shanghai 980 Beijing handan 400 Beijing Chongqing 442 Beijing Taiyuan 200 Taiyuan Chongqing 193 Taiyuan handan 150 handan Shanghai 499 Chongqing Shanghai 448 Beijing 113 Shanghai 120 Chongqing 89 Taiyuan 50 handan 80 Yangqu 45 5 Beijing Shanghai Chongqing Yangqu Taiyuan London Tokyo Yangqu Shanghai Beijing 3 1 London NewYork 803 London 549587 NewYork 779876 Paris 448676 4 NewYork London London Paris MianYang Taigu London NewYork 5 4 A B 1000 B C 2000 A C 355000 E D 4164 A 12 B 21 C 12 D 4 E 9 5 A C A D E A A F X Y
Sample output:
Case #1: query (1): from A to C: The lest cost from A to C is: 3021. There is only one route which can satisfy the lest cost. The fewest number of transfer stations can be: 3. A->B->C. query (2): from A to D: Sorry,there are no way from A to D. query (3): from E to A: Sorry,there are no way from E to A. query (4): from A to F: F is not on this map. query (5): from X to Y: X and Y are not on this map. Case #2: query (1): from Beijing to Shanghai: The lest cost from Beijing to Shanghai is: 979. There are 3 routes which can satisfy the lest cost. The fewest number of transfer stations can be: 3. Beijing->Chongqing->Shanghai. query (2): from Chongqing to Yangqu: Sorry,there are no way from Chongqing to Yangqu. query (3): from Taiyuan to London: London is not on this map. query (4): from Tokyo to Yangqu: Tokyo is not on this map. query (5): from Shanghai to Beijing: The lest cost from Shanghai to Beijing is: 979. There are 3 routes which can satisfy the lest cost. The fewest number of transfer stations can be: 3. Shanghai->handan->Beijing. Case #3: query (1): from NewYork to London: The lest cost from NewYork to London is: 803. There is only one route which can satisfy the lest cost. The fewest number of transfer stations can be: 2. NewYork->London. query (2): from London to Paris: Sorry,there are no way from London to Paris. query (3): from MianYang to Taigu: MianYang and Taigu are not on this map. query (4): from London to NewYork: The lest cost from London to NewYork is: 803. There is only one route which can satisfy the lest cost. The fewest number of transfer stations can be: 2. London->NewYork. Case #4: query (1): from A to C: The lest cost from A to C is: 3021. There is only one route which can satisfy the lest cost. The fewest number of transfer stations can be: 3. A->B->C. query (2): from A to D: Sorry,there are no way from A to D. query (3): from E to A: Sorry,there are no way from E to A. query (4): from A to F: F is not on this map. query (5): from X to Y: X and Y are not on this map.

AC happy~

xzc
2020/2/11 9:52

Apare_xzc 78 original articles were published, 60 were praised, 20,000 visits+ Private letter follow

10 February 2020, 21:08 | Views: 7798

Add new comment

For adding a comment, please log in
or create account

0 comments