Uva11374[airport Express] Dijkstra/spfa+ Enumeration __ Shortest Path algorithm

Source: Internet
Author: User
Tags ticket
Topic link in the city of Iokh, the Airport Express is the preferred means of transport for the public to the airport. The Airport Express line is divided into economic line and commercial line two kinds, line, speed and price are different. You have a business line ticket, you can do a business line, and other times can only ride the economic line. Assuming the transfer time is negligible, your job is to find the quickest route to the airport. SOLUTION:DIJKSTRA/SPFA preprocessing the distance from each point to the start and end points, and then enumerates the commercial lines, the Complexity O (mlogn+k)
#include <queue> #include <cstdio> #include <vector> #include <cstring> #include <iostream
> #include <algorithm> using namespace std;

#define INF 0x3f3f3f3f const int N = 505;
int n, ans, S, E;
int d1[n], d2[n], p1[n], p2[n];
    struct edge{int U, V, W;
Edge (int u, int v, int w): U (U), V (v), W (w) {}};
    struct heapnode{int dist, u;
    BOOL operator< (const heapnode& RHS) const{return dist>rhs.dist;
}
};
    struct dijkstra{int n;
    int d[n], p[n];
    BOOL Vis[n];
    vector<edge>edges; 
    vector<int>g[n];
        void init (int n) {this->n=n;
        for (int i=1; i<=n; i++) g[i].clear ();
    Edges.clear ();
            } void Addeage (int u, int v, int w) {edges.push_back (Edge) {u,v,w});
        int m=edges.size ();
    G[u].push_back (m-1);
        } void Dijkstra (int s) {for (int i=1; i<=n; i++) D[i]=inf, p[i]=0;
        memset (Vis) (vis,0,sizeof); Priority_queue

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.