HDU1839

来源:互联网 发布:cf英雄武器抽奖 软件 编辑:程序博客网 时间:2024/06/08 02:50

Delay Constrained Maximum Capacity Path


Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 969 Accepted Submission(s): 301


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


Author
Mugurel Ionut Andreica


Source
Politehnica University of Bucharest Local Team Contest 2007

题意:有一些矿物,要从1点运送到n点,n个点,m条边,每条边有路过要花费的时间和容量,运送到n点的时间必须在t内,问最多能运送多少矿物。

分析:时间肯定是越短越好,所以很容易想到了最短路,用最短路可以跑出最少的时间,然后二分容量,如果这条边的容量小于二分的容量就给个标记表示这条边不能跑,标记完后跑最短路(时间),如果时间小于t就可以,慢慢就可以二分处答案了。

#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int MAXN=10010;const int MAXM=100010;const int INF=1<<30;int dis[MAXN],head[MAXN],vis[MAXN];int cnt,n;struct seg{    int v,next,cost,cap,flag;   //flag表示这条边能不能走}edge[MAXM];void init(){    memset(head,-1,sizeof(head));    cnt=0;}void add_edge(int u,int v,int cost,int cap){    edge[cnt].v=v;    edge[cnt].cap=cap;    edge[cnt].cost=cost;    edge[cnt].next=head[u];    edge[cnt].flag=1;    head[u]=cnt++;}int spfa(int s){    for(int i=1;i<=n;i++)    {        dis[i]=INF;        vis[i]=0;    }    dis[s]=0;    vis[s]=1;    queue<int> q;    q.push(s);    while(!q.empty())    {        int u=q.front();        q.pop();        vis[u]=0;        for(int i=head[u];i!=-1;i=edge[i].next)        {            int v=edge[i].v;            if(dis[v]>dis[u]+edge[i].cost&&edge[i].flag)            {                dis[v]=dis[u]+edge[i].cost;                if(!vis[v])                {                    vis[v]=1;                    q.push(v);                }            }        }    }    if(dis[n]!=INF)        return dis[n];    return INF;}int main(){    int cas,t,m,i,j,a,b,c,d;    scanf("%d",&cas);    while(cas--)    {        scanf("%d%d%d",&n,&m,&t);        init();        int r=0,l=0;;        while(m--)        {            scanf("%d%d%d%d",&a,&b,&c,&d);            add_edge(a,b,d,c);            add_edge(b,a,d,c);            r=max(r,c);        }        int ans=0;        while(l<=r)        {            int mid=(l+r)>>1;            for(i=0;i<cnt;i++)                if(edge[i].cap<mid)                edge[i].flag=0;            int temp=spfa(1);            if(temp<=t)            {                ans=max(ans,mid);                l=mid+1;            }            else                r=mid-1;            for(i=0;i<cnt;i++)                edge[i].flag=1;        }        printf("%d\n",ans);    }    return 0;}


0 0
原创粉丝点击