Ultraviolet A 11374 Airport Express (dijkstra + enumeration + edge output), 11374 dijkstra
Question: How many stations are there for n, s, e, and n? s and e are the start and end points. Then there are m economic routes, next, there will be k commercial lines. You can only hold one commercial line at most. Now you need to find the shortest circuit from s to e, it also outputs the nodes it passes through and the station with a commercial line.
Train of Thought: in fact, this question is your understanding of dijkstra. The meaning of d array is the shortest distance from the starting point to the point I. So every time you look for a business route, can I compare the minimum value of d [e] following the start point to u + the minimum value from the end point to v + w [u] [v]? Finally, we can use recursive output paths.
AC code:
#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<vector>using namespace std;#define inf 1e9const int maxn=100000;int e_cnt;struct Edge{ int from,to,dist;};struct heapnode{ int d,u; bool operator < (const heapnode& rhs) const { return d>rhs.d; }};int n,m;vector<int >g[maxn];vector<Edge >edge;bool vis[maxn];int d[maxn];int p[maxn];void init(){ for(int i=0;i<n;i++)g[i].clear(); edge.clear();}void addedge(int from,int to,int dist){ edge.push_back((Edge){from,to,dist}); e_cnt=edge.size(); g[from].push_back(e_cnt-1);}void dijkstra(int s){ priority_queue