Hdu1839 binary + adjacent table + Dijkstra + queue Optimization

Source: Internet
Author: User

Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission (s): 544 Accepted Submission (s): 192


Problem Description
Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. the vertex numbered with 1 corresponds to a mine from where some precious minerals are extracted. the vertex numbered with N corresponds to a minerals processing factory. each edge has an associated travel time (in time units) and capacity (in units of minerals ). it has been decided that the minerals which are extracted from the mine will be delivered to the factory using a single path. this path shoshould have the highest capacity possible, in order to be able to transport simultaneously as your units of minerals as possible. the capacity of a path is equal to the smallest capacity of any of its edges. however, the minerals are very sensitive and, once extracted from the mine, they will start decomposing after T time units, unless they reach the factory within this time interval. therefore, the total travel time of the chosen path (the sum of the travel times of its edges) shocould be less or equal to T.

 

Input
The first line of input contains an integer number X, representing the number of test cases to follow. the first line of each test case contains 3 integer numbers, separated by balancer: N (2 <= N <= 10.000), M (1 <= M <= 50.000) and T (1 <= T <= 500.000 ). each of the next M lines will contain in four integer numbers each, separated by blanks: A, B, C and D, meaning that there is an edge between vertices A and B, having capacity C (1 <= C <= 2.000.000.000) and the travel time D (1 <= D <= 50.000 ). A and B are different integers between 1 and N. there will exist at most one edge between any two vertices.

 

Output
For each of the X test cases, in the order given in the input, print one line containing the highest capacity of a path from the mine to the factory, considering the travel time constraint. there will always exist at least one path between the mine and the factory obbeying the travel time constraint.

 

Sample Input
2
2 1 10
1 2 13 10
4 4 20
1 2 1000 15
2 4 999 6
1 3 100 15
3 4 99 4

Sample Output
13
99


Question: For m pipelines, each pipeline has the maximum capacity that can be transported and the time consumed c, t

Now there is something to be transported from 1 to n, it must be completed within T, find the maximum capacity that meets the conditions of transport

Analysis: sort the maximum capacity of the given m pipelines, and then calculate the shortest time from 1 to n for the second capacity.

# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <vector> # include <iomanip> # define INF 99999999 using namespace std; const int MAX = 10000 + 10; int s [MAX * 5], n, m, t; int size, head [MAX], dist [MAX]; bool mark [MAX]; typedef pair <int, int> mp; struct Edge {int v, c, t, next; Edge () {} Edge (int & V, int & C, int & T, int NE XT): v (V), c (C), t (T), next (NEXT) {}} edge [MAX * 5*2]; inline void Init (int num) {memset (head,-1, sizeof (int) * (num + 2); size = 0;} inline void InsertEdge (int u, int v, int & c, int & t) {edge [size] = Edge (v, c, t, head [u]); // head [u] = size ++;} inline bool Dijkstra (int s, int t, int c, int T) {for (int I = 1; I <= n; ++ I) mark [I] = false, dist [I] = INF; dist [s] = 0, mark [s] = true; priority_queue <mp, vector <mp>, greater <mp> q; mp oq; Q. push (mp (0, s); while (! Q. empty () {oq = q. top (); q. pop (); if (oq. first> T) return false; if (oq. second = t) return dist [t]; // dist [t] <= T; mark [oq. second] = true; for (int I = head [oq. second]; I! =-1; I = edge [I]. next) {int v = edge [I]. v; if (mark [v] | edge [I]. c <c) continue; if (oq. first + edge [I]. t <dist [v]) {dist [v] = oq. first + edge [I]. t; q. push (mp (dist [v], v) ;}} return false; // cannot reach t} int main () {int num, u, v, c, t; cin> num; while (num --) {scanf ("% d", & n, & m, & t); Init (n ); for (int I = 0; I <m; ++ I) {scanf ("% d", & u, & v, & c, & T); InsertEdge (u, v, c, T); InsertEdge (v, u, c, T); s [I] = c;} sort (s, s + m); int left = 0, right = 0, mid; for (int I = 1; I <m; ++ I) if (s [I]! = S [I-1]) s [+ right] = s [I]; while (left <= right) {mid = left + right> 1; if (Dijkstra (1, n, s [mid], t) left = mid + 1; else right = mid-1;} printf ("% d \ n ", s [right]);} return 0 ;} # include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <vector> # include <iomanip> # define INF 99999999 using namespace std; const int MAX = 10000 + 10; int s [MAX * 5], N, m, t; int size, head [MAX], dist [MAX]; bool mark [MAX]; typedef pair <int, int> mp; struct Edge {int v, c, t, next; Edge () {} Edge (int & V, int & C, int & T, int NEXT): v (V ), c (C), t (T), next (NEXT) {}} edge [MAX * 5*2]; inline void Init (int num) {memset (head, -1, sizeof (int) * (num + 2); size = 0;} inline void InsertEdge (int u, int v, int & c, int & t) {edge [size] = Edge (v, c, t, head [u]); // head [u] = size ++ ;} inline bool Dijkstra (int s, int t, int c, Int T) {for (int I = 1; I <= n; ++ I) mark [I] = false, dist [I] = INF; dist [s] = 0, mark [s] = true; priority_queue <mp, vector <mp>, greater <mp> q; mp oq; q. push (mp (0, s); while (! Q. empty () {oq = q. top (); q. pop (); if (oq. first> T) return false; if (oq. second = t) return dist [t]; // dist [t] <= T; mark [oq. second] = true; for (int I = head [oq. second]; I! =-1; I = edge [I]. next) {int v = edge [I]. v; if (mark [v] | edge [I]. c <c) continue; if (oq. first + edge [I]. t <dist [v]) {dist [v] = oq. first + edge [I]. t; q. push (mp (dist [v], v) ;}} return false; // cannot reach t} int main () {int num, u, v, c, t; cin> num; while (num --) {scanf ("% d", & n, & m, & t); Init (n ); for (int I = 0; I <m; ++ I) {scanf ("% d", & u, & v, & c, & T); InsertEdge (u, v, c, T); InsertEdge (v, u, c, T); s [I] = c;} sort (s, s + m); int left = 0, right = 0, mid; for (int I = 1; I <m; ++ I) if (s [I]! = S [I-1]) s [+ right] = s [I]; while (left <= right) {mid = left + right> 1; if (Dijkstra (1, n, s [mid], t) left = mid + 1; else right = mid-1;} printf ("% d \ n ", s [right]);} 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.