UVA 11374-airport Express (Dijstra)

Source: Internet
Author: User

UVA 11374-airport Express

Topic links

Test instructions: Given some economic lines, and some business lines, the business line sits at most once, each line has a time, ask the shortest time

Ideas: From the beginning, the end of each to do a dijstra, and then enumerate the business line, you can calculate the total time, and finally find the total time minimum

Code:

#include <cstdio> #include <cstring> #include <vector> #include <queue>using namespace std;# Define INF 0x3f3f3f3fconst int maxnode = 505;struct Edge {int u, V, Dist; Edge () {}edge (int u, int v, int dist) {this->u = U;this->v = V;this->dist = dist;}}; struct Heapnode {int d, u; Heapnode () {}heapnode (int d, int u) {this->d = D;this->u = u;} BOOL operator < (const heapnode& c) Const {return d > c.d;}}; struct Dijkstra {int n, m;vector<edge> edges;vector<int> g[maxnode];bool done[maxnode];int D[MAXNODE], p[ maxnode];void init (int tot) {n = tot;for (int i = 0; i < n; i++) g[i].clear (); Edges.clear ();} void Add_edge (int u, int v, int dist) {edges.push_back (Edge (U, V, Dist)); m = Edges.size (); G[u].push_back (m-1);} void print (int s, int e) {//shun Xuif (s = = e) {printf ("%d", E + 1); return;} Print (S, edges[p[e]].u);p rintf ("%d", E + 1);} void Print2 (int s, int e) {//ni Xuif (s = = e) {printf ("%d\n", E + 1); return;} printf ("%d", E + 1);p Rint2 (S, EDGES[P[E]].U);} void Dijkstra (int s) {priority_queue

UVA 11374-airport Express (Dijstra)

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.