UVA 10537-the toll! Revisited (Dijstra extension)

Source: Internet
Author: User

UVA 10537-the toll! Revisited

Topic links

Test instructions: Given an no-map, capital letter is the city, the small letter is the village, after the city has paid the tolls for the current goods of%5, passing village fixed 1, given the starting point and to the destination to the rest of the goods, ask at least how much cargo to take the road, and output path, if there are many scenarios, require the minimum

Idea: The inverse of the Dijstra, D array meaning into the node need at least so many goods, and then reverse the map, from the end point to the beginning of the reverse do again

The problem is in the pit. Not the output of the city exists, such as the following set of examples
0
1 A A
Should output
1
A

Code:

#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <cmath> using namespace Std;const int maxnode = 105;typedef long Long type;const Type INF = (1ll<<61); struct Edge {int u, v; Type Dist; Edge () {}edge (int u, int v, Type dist) {this->u = U;this->v = V;this->dist = dist;}}; struct Heapnode {Type d;int u; Heapnode () {}heapnode (Type D, int u) {this->d = D;this->u = u;} BOOL operator < (const heapnode& c) Const {return d > c.d;}}; Char to[255];struct Dijkstra {int n, m;vector<edge> edges;vector<int> g[maxnode];bool Done[maxnode]; Type d[maxnode];int 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, Type Dist) {edges.push_back (Edge (U, V, Dist)); m = Edges.size (); G[u].push_back (m-1);} void print (int e) {if (p[e] = =-1) {printf ("%c\n", To[e]); return;} printf ("%c-", To[e]);p rint (EDGES[P[E]].U);} void Dijkstra (Type start, int s) {Priority_queue

UVA 10537-the toll! Revisited (Dijstra extension)

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.