HDU 2962 Trucking Shortest circuit + two points

Source: Internet
Author: User
Tags cas

Topic Source HDU 2962 Trucking

Test instructions: give you a graph n point M Edge gives the starting point S end e and the maximum withstand height where each road has a limit of height and the length of the road to the maximum can pass from S to e height and the maximum height of the premise of the shortest path

Train of thought: two-point height to find the shortest circuit without a special sentence

#include <cstdio> #include <algorithm> #include <queue> #include <vector> using namespace std;
const int MAXN = 1010;
struct Edge {int u, V, H, W;};
	struct Heapnode {int u, D;
	BOOL operator < (const heapnode& RHS) Const {return d > rhs.d;
}
};
Vector <edge> G[MAXN];
int DIS[MAXN];
BOOL VIS[MAXN];
int n, m;
int S, E;
	void Dijkstra (int h) {for (int i = 0; I <= N; i++) dis[i] = 999999999;
	memset (DIS, 0x7f, sizeof (DIS));
	Dis[s] = 0;
	Memset (Vis, false, sizeof (VIS));
	Priority_queue <HeapNode> Q;
	Q.push ((Heapnode) {s, 0}); while (!
		Q.empty ()) {Heapnode x = Q.top ();
		Q.pop ();
		int u = x.u;
		if (Vis[u]) continue;
		Vis[u] = true;
			for (int i = 0; i < g[u].size (); i++) {Edge e = g[u][i];
			if (E.h < h) continue;
			int v = e.v;
				if (Dis[v] > x.d + e.w) {Dis[v] = x.d + e.w;	
			Q.push ((Heapnode) {V, dis[v]});
	}}}} int main () {int cas = 0; while (scanf ("%d%d", &n, &m) && (N+m)) {for (int i = 0; I <= N; i++) g[i].clear ();
			for (int i = 0; i < m; i++) {int u, V, H, W;
			scanf ("%d%d%d", &u, &v, &h, &w);
			if (h = =-1) h = 999999999;
			G[u].push_back (Edge) {u, V, h, w});			
		G[v].push_back (Edge) {V, U, h, w});
		} int lim;
		scanf ("%d%d%d", &s, &e, &lim);
		int L = 0, r = Lim, ans =-1, Len;
			while (L <= r) {int mid = (L + r) >> 1;
			Dijkstra (mid);
				if (dis[e]! = 999999999) {ans = mid;
				len = Dis[e];
			L = mid + 1;
			} else {r = mid-1;
		}} if (cas++) puts ("");
		printf ("Case%d:\n", CAs);
			if (ans = =-1) {puts ("Cannot reach destination");
		Continue
		} printf ("Maximum height =%d\n", ans);
	printf ("Length of shortest route =%d\n", Len);
} return 0; }


 

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.