UV 10537 The Toll! Revisited (transient deformation)

Source: Internet
Author: User

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 

 

Related Article

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.