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