Ultraviolet A 11374 Airport Express (dijkstra + enumeration + edge output), 11374 dijkstra

Source: Internet
Author: User

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


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.