Ultraviolet A 11374 Airport Express Line dijistra + path

Source: Internet
Author: User

Link to the question: Ultraviolet 11374 Airport Express


Airport Express
Time limit:1000 ms   Memory limit:Unknown   64bit Io format:% LLD & % LlU

[Submit] [Go Back] [Status]

Description

Problem D: Airport Express

In a small city called iokh, a train service,Airport-Express, Takes residents to the airport more quickly than other transports. There are two types of trains in airport-Express,Economy-xpressAndCommercial-xpress. They travel at different speeds, take different routes and have different costs.

Jason is going to the airport to meet his friend. he wants to take the specified cial-xpress which is supposed to be faster, but he doesn't have enough money. luckily he has a ticket for the specified cial-xpress which can take him one station forward. if he used the ticket wisely, he might end up saving a lot of time. however, choosing the best time to use the ticket is not easy for him.

Jason now seeks your help. the routes of the two types of trains are given. please write a program to find the best route to the destination. the program shoshould also tell when the ticket shoshould be used.

Input

The input consists of several test cases. Consecutive Cases are separated by a blank line.

The first line of each case contains 3 integers, namelyN,SAndE(2 ≤N≤ 500, 1 ≤S,EN), Which represent the number of stations, the starting point and where the airport is located respectively.

There is an integerM(1 ≤M≤ 1000) representing the number of connections between the stations of the economy-xpress. The nextMLines give the information of the routes of the economy-xpress. Each consists of three IntegersX,YAndZ(X,YN, 1 ≤Z≤ 100). This meansXAndYAre connected and it takesZMinutes to travel between these two stations.

The next line is another integerK(1 ≤K≤ 1000) representing the number of connections between the stations of the specified cial-xpress. The nextKLines contain the information of the specified cial-xpress in the same format as that of the economy-xpress.

All connections are bi-directional. You may assume that there is exactly one optimal route to the airport. There might be cases where you must use your ticket in order to reach the airport.

Output

For each case, You shocould first list the number of stations which Jason wowould visit in order. On the next line, output"Ticket not used"If you decided not to use the ticket; otherwise, state the station where Jason shoshould get on the train of specified cial-xpress. finally, print the total time for the journey on the last line. consecutive sets of output must be separated by a blank line.

Sample Input
4 1 441 2 21 3 32 4 43 4 512 4 3

Sample output
1 2 425

Problemsetter: Raymond Chun
Originally appeared in cxpc, Feb. 2004




Question:

In iokh, the Airport Express Line is the first choice for citizens to go to the airport from the city. The Airport Express Line is divided into two types: Economic line and commercial line. The line, speed and price are different. You have a commercial line ticket, which can be used as a commercial line. In other cases, you can only take the economical line. Assume that the transfer time is negligible. Your task is to find the fastest route to the airport.

Analysis:

Commercial lines can only sit on one site, which can be enumerated, and compare all possible optimal solutions.

If we use commercial line tickets to move from Station A to Station B, the two lines from the starting point to a and from B to the ending point should be the most Short Circuit for the economic line network. In other words, we only need to perform the two most short circuits from the start point to the end point, and record the shortest time from the start point to the end point F (), and the shortest time g (B) from each point B to the end point. The total time is f (a) + T (a, B) + g (B), where T (, b) for commercial purposes. This is the smallest value.

For Path output, because it has been recorded in P, you can print the path through recursive operations.

Code:

# Include <iostream> # include <cstdio> # include <cstring> # include <queue> # include <vector> using namespace STD; # define maxn 550 # define INF 0x3f3f3fstruct edge {int from, to, DIST ;}; struct heapnode {int D, U; bool operator <(const heapnode & RHs) const {return D> RHS. d ;}}; int N, S, E; vector <edge> edges; vector <int> G [maxn]; bool vis [maxn]; int d [maxn], P [maxn], P1 [maxn], P2 [maxn]; void Init (int n ){ For (INT I = 0; I <= N; I ++) g [I]. clear (); edges. clear ();} void addedge (int from, int to, int Dist) {// undirected graph, each edge needs to call addedge edges twice. push_back (edge) {from, to, DIST}); int x = edges. size (); G [from]. push_back (x-1);} void Dijkstra (INT s) {priority_queue 

Ultraviolet A 11374 Airport Express Line dijistra + path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.