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)