UVA 11374 Airport Express (Dijkstra)

Source: Internet
Author: User



Test instructions: In the city of Iokh, the Airport Express is the preferred means of transportation from the city to the airport. Airport Express line is divided into two kinds of economic and commercial lines, line, speed and price are different. You have a commercial line ticket, you can do a commercial line, and other times you can only take the economic line. Assuming the transfer time is negligible, your task is to find the quickest route to the airport.

Analysis: Enumeration of commercial lines T (A, A, b), the total time is f (a) +t (A, a) +g (b), F and G with two times Dijkstra to calculate, with S as the starting point of the Dijkstra and E as the starting point of the Dijkstra;

Note: It is possible to do only a slow train can not reach the end, at this time must do a station express, if according to the slow train must reach the end point and then print from the beginning of the path may be error, because there is no full path, when the station to the end from the other side should be printed

#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <iostream > #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack& Gt  #include <string> #include <map> #include <set> #define EPS 1e-6 #define LL Long long using namespace std; const int MAXN = 550;const int INF = 100000000;int N, S, E, M, K;vector<pair<int, int> > Kuai[maxn];int kase; Dijkstra struct Edge {int from, to, Dist; Edge (int u = 0, int v = 0, int d = 0): From (U), to (v), Dist (d) {}};struct Heapnode {///used to the node int d of the priority queue, U;bool operator < (const heapnode& RHS) Const {return d > rhs.d;}};  struct Dijkstra {int n, m;  Points and the number of sides vector<edge> edges;   Edge list vector<int> G[MAXN];            Number of edges starting at each node bool DONE[MAXN];                Whether it has been permanently numbered int D[MAXN];                s to various points of distance int P[MAXN]; The last edge of the shortest path is void init (int n) {this->n = n;for (int i = 0; i < n; i++) g[i].clear (); Edges.clear ();} void Addedge (int from, int to, int dist) {//If the graph needs to be called two times Edges.push_back (Edge (from, to, dist); m = Edges.size ();  G[from].push_back (m-1);} void Dijkstra (int s) {//for S to all points distance, 0 for starting point, 1 for end point priority_queue

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA 11374 Airport Express (Dijkstra)

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.