Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1876 Accepted Submission(s): 619
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
题目大意:
给你n个点和m条路,现在要把一些矿物从1运到n限制时限是T,每条路都有一个限制载重的值和经过所花费的时间,
现在要保证运输的矿物尽可能的多并未超过时间T
题目思路:
因为要保证矿物重量尽可能的多,所以我们可以二分重量,而mid值就是我们当前的重量,所以在mid值以下的的路可以
不考虑,每次二分时都重新建图,把权值大于等于mid的边连起来,在跑一边最短路,如果dis[n]<=T,说明还可以增大重量,
否则重量大了
AC代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int maxn = 1e4+100;
const int maxm = 5e4+100;
const int inf = 2e9;
class Edge{
public:
int v,w,nex;
};
class Point{
public:
int u,v,t,w;
};
class BiSpfa{
public:
int n,m,t,e;
int Maxt;
int hed[maxn],dis[maxn],vis[maxn];
Edge edge[maxm<<1];
Point p[maxm<<1];
queue<int>q;
void add(int u,int v,int w){
edge[e].v = v,edge[e].w = w,edge[e].nex = hed[u],hed[u]=e++;
edge[e].v = u,edge[e].w = w,edge[e].nex = hed[v],hed[v]=e++;
}
void init(){
int T;cin>>T;
while(T--){
scanf("%d%d%d",&n,&m,&t);Maxt = -1;
memset(vis,0,sizeof(vis));
for(int i=1;i<=m;i++){
scanf("%d%d%d%d",&p[i].u,&p[i].v,&p[i].t,&p[i].w);
Maxt=max(Maxt,p[i].t);
}
solve();
}
}
void initGraph(int mid){
memset(hed,-1,sizeof(hed));
e = 1;
for(int i=1;i<=m;i++)
if(p[i].t>=mid)add(p[i].u,p[i].v,p[i].w);
}
void spfa(){
for(int i=2;i<=n;i++)dis[i]=inf;
dis[1]=0,vis[1]=1;q.push(1);
while(!q.empty()){
int u = q.front();q.pop();vis[u]=0;
for(int i= hed[u];~i;i=edge[i].nex){
int v = edge[i].v;
if(dis[v]>dis[u]+edge[i].w){
dis[v]=dis[u]+edge[i].w;
if(!vis[v]){vis[v]=1;q.push(v);}
}
}
}
}
void solve(){
int l=1,r=Maxt,mid,ans;
while(l<=r){
mid = l+(r-l)/2;
initGraph(mid);
spfa();
if(dis[n]<=t)l=mid+1,ans=mid;
else r=mid-1;
}
printf("%d\n",ans);
}
}bs;
int main()
{
bs.init();
return 0;
}