题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1839
Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1927 Accepted Submission(s): 646
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 should have the highest capacity possible, in order to be able to transport simultaneously as many 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) should 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 blanks: N (2 <= N <= 10.000), M (1 <= M <= 50.000) and T (1 <= T <= 500.000). Each of the next M lines will contain 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
题目大意:给你一张无向图,每条边有个流量c和时间t,求从s点到e点在规定时间T内,最大的流量。
解题思路:spfa+二分
二分每条边的流量,在某个流量限制下,求出从s点到e点的最短时间,看是否满足时间条件。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ull;
const int N = 10009;
const int M = 50800;
const int INF = 0x7fffffff;
const double Pi = acos(-1.0);
struct Edge{
int nd,cap,tm;
Edge*next;
}m_edge[M*2];
Edge*head[N];
int dist[N],vis[N],Ecnt;
void init()
{
Ecnt = 0;
fill( head , head+N , (Edge*)0 );
}
void mkEdge( int a , int b , int c , int t )
{
m_edge[Ecnt].nd = b;
m_edge[Ecnt].cap = c;
m_edge[Ecnt].tm = t;
m_edge[Ecnt].next = head[a];
head[a] = m_edge+Ecnt++;
}
void spfa( int limit )
{
fill( dist , dist+N , INF );
fill( vis , vis+N , 0 );
dist[1] = 0;
queue<int>point;
point.push(1);
vis[1] = 1;
while( !point.empty() ){
int s = point.front();
point.pop();
vis[s] = 0;
for( Edge*p = head[s] ; p ; p = p->next ){
int t = p->nd;
if( dist[t]>dist[s]+p->tm && p->cap >= limit ){
dist[t] = dist[s]+p->tm;
if( !vis[t] ){
point.push(t);
vis[t] = 1;
}
}
}
}
}
int main()
{
int T,n,m,rt,rec[M],tot=0;
scanf("%d",&T);
while( T-- ){
init();
scanf("%d%d%d",&n,&m,&rt);
int a,b,c,t;
for( int i = 0 ; i < m ; ++i ){
scanf("%d%d%d%d",&a,&b,&c,&t);
mkEdge( a , b , c , t );
mkEdge( b , a , c , t );
rec[i] = c;
}
sort( rec , rec+m );
int ans,mid,l=0,r=m-1;
while( l<=r ){
mid = (l+r)/2;
spfa(rec[mid]);
if( dist[n] > rt ) r = mid-1;
else{
l = mid+1; ans = rec[mid];
}
}
printf("%d\n",ans);
}
return 0;
}