# HDU 1839 Delay constrained Maximum Path (two points + shortest)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1839

Topic:

Delay constrained Maximum Capacity Path
Time limit:10000/10000 MS (java/others) Memory limit:65535/65535 K (java/others)
Total submission (s): accepted submission (s): 98

Problem Description
Consider a 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. The vertex numbered with N corresponds to a minerals processing factory. Each edge has a associated travel time (in time units) and capacity (in units of minerals). It has been decided that's minerals which are extracted from the mine would be delivered to the ' factory using a single PA Th. This path should have the highest capacity possible, in order to is able to transport simultaneously as many units of mine RALs 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 to the mine, they'll 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 it edges) should be less or equal to T.

Input
The "a" of input contains an integer number X, representing the number of test cases to follow. The "a" of each test case contains 3 integer numbers separated by blanks:n (2 <= N <= 10.000), m (1 <= m <= 50.000) and T (1 <= t <= 500.000). Each of the next M lines would contain four integer numbers each, separated by blanks:a, B, C and D, meaning this there is An edge between vertices A and B, has 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'll exist at the most one edge between any two vertices.

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

Sample Input

```2
2 1 1 2 4 4 1 2
1000
2 4 999 6
1 3 3 4 99 4```

Sample Output

```
99```

The main effect of the topic:
There are n points, point 1 for mining areas of precious minerals, point n for processing plants, there are M-bar two-way connected edges connecting these points. The transport capacity of each side is C and the delivery time is D.
They want to select a path from 1 to N to transport the total time of this path within T, under this premise, to make the path of the transport capacity as large as possible.
The transport capacity of a path depends on the side with the smallest transport capacity in the path.

Analysis and Summary:
Because the capacity of each path depends on the minimum capacity of all the edges in the path, we can enumerate the minimum capacity with this.

But if an enumeration of one capacity, that is obviously too inefficient.

Through analysis, we can see that, if the minimum capacity of the larger, then meet the requirements of the less path, so, according to the size of capacity, the number of paths is monotonous.

With the monotony, we can use the two-point method.

As long as the capacity from large to small to sort, and then two points, will soon be able to calculate the answer.

Code:

```#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <que

Ue> using namespace std;
const int INF = 0x7fffffff;
const int VN = 10005;

const int EN = 50005; struct Edge{int v,next,cap,time;}

E[EN*2];
int n, m, T;
int size;
int Cap[en];
int D[VN];
int TIME[VN];
int limit;

BOOL INQ[VN];
void Init () {size=0;
} void Addedge (int u,int v,int c,int d) {e[size].v=v;
E[size].cap=c;
E[size].time=d;
int Dijkstra (int src) {memset (inq, 0, sizeof (INQ));
for (int i=1; i<=n; ++i) D[i]=inf;
D[SRC] = 0;
queue<int>q;
Q.push (SRC);
while (!q.empty ()) {int u = q.front (); Q.pop ();
Inq[u] = false; for (int e=head[u]; E!=-1 e=e[e].next) if (e[e].cap>=limit) {int tmp = d[u]+E[e].time;
if (D[E[E].V] > tmp) {D[E[E].V] = tmp;
if (!INQ[E[E].V]) {INQ[E[E].V] = true;
Q.push (E[E].V);
}}} return d[n];
int main () {int T, u, V, C, D;
scanf ("%d", &t);
while (t--) {scanf ("%d%d%d", &n,&m,&t);
Init ();
for (int i=0; i<m; ++i) {scanf ("%d%d%d%d", &u,&v,&c,&d);
Cap[i]=c;
Sort (Cap, cap+m,greater<int> ());
Two-point solution int left=0, right=m-1, mid;
while (left<right) {mid = (left+right) >>1;
Limit = Cap[mid];
int Tmp=dijkstra (1);
if (Tmp==inf | | tmp>t) {left = mid+1;
} else{    Right=mid;
} printf ("%d\n", Cap[left]);
return 0; }```

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Related Keywords:

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.