From s to t, every time a village passes through a village, one unit of goods will be paid. When a town passes through, every 20 goods will be paid one, and the minimum cost path of the Lexicographic Order will be obtained.
Use the shortest circuit to solve the problem. Run the shortest path from the terminal. For the Edge Weight of the edge <u, v>, if u is a village, the edge weight is 1. When u is a town, the edge weight is min {key | key-(key + 19)/20 = d [u]}.
After finding the shortest path, it is okay to go from the start point dfs along the edge that satisfies the shortest distance and has the smallest Lexicographic Order ~
# Include <algorithm> # include <iostream> # include <cstring> # include <cstdlib> # include <fstream> # include <sstream> # include <string> # include <vector> # include <cstdio> # include <queue> # include <stack> # include <cmath> # include <map> # include <set> # define FF (I, a, B) for (int I = a; I <B; I ++) # define FD (I, a, B) for (int I =; i> = B; I --) # define REP (I, n) for (int I = 0; I <n; I ++) # define CLR (a, B) memset (a, B, sizeof (a) # define deb Ug puts ("** debug **") # define PB push_back # define LL long longusing namespace std; LL bin (LL k) // perform the following two-point search for the minimum cargo required before passing through the town: {ll l = 0, R = k * 2 + 1, M, ans; while (L <= R) {M = (L + R)> 1; LL tmp = M-(M + 19)/20; if (tmp> k) R = M-1; else if (tmp = k) ans = M, R = M-1; else L = M + 1;} return ans;} const int maxn = 111; const ll inf = 10000000000; int n, m, s, t; string name, ans; struct heap {LL d; int u; bool Operator <(const heap rhs) const {return d> rhs. d ;}}; vector <int> G [maxn]; bool done [maxn]; LL d [maxn], P; map <char, int> id; inline void init () {REP (I, maxn) G [I]. clear (); n = 0; name. clear (); ans. clear (); id. clear () ;}int get (char c) {if (! Id. count (c) id [c] = n ++, name. PB (c); return id [c];} void dij (int s) {REP (I, n) d [I] = INF; d [s] = P; priority_queue