HDU - 1839 Delay Constrained Maximum Capacity Path

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

这道题还是一道二分的题,毕竟直接枚举也不太现实

#include <iostream>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 1e16
using namespace std;
/*
第一次双向队列过题,爽啊
*/

typedef long long ll;
int cnt;
int n,m,limit;
int head[100010];
ll dis[50010];
int vis[50010];
struct node
{
    int t,c;
}w[50010];
struct edge
{
    int v,next;
    int time,capa;
}Edge[100010];
void add_edge(int u,int v,int c,int t)
{
    Edge[cnt].v=v;
    Edge[cnt].time=t,Edge[cnt].capa=c;
    Edge[cnt].next=head[u];
    head[u]=cnt++;
}

int cmp(node a,node b)
{
    if(a.c<b.c)
        return 1;
    else
        return 0;
}

ll spfa(int road_limit)
{
    for(int i=0;i<=n;i++)
        dis[i]=INF;
    memset(vis,0,sizeof(vis));
    dis[1]=0;
    vis[1]=1;
    deque<int> q;
    q.push_back(1);
    while(q.size())
    {
        int now=q.front();
        q.pop_front();
        vis[now]=0;
        for(int i=head[now];i!=-1;i=Edge[i].next)
        {
            int v=Edge[i].v,t=Edge[i].time,c=Edge[i].capa;
            if(c>=road_limit&&dis[v]>dis[now]+t)//满足道路承载能力,我们才回去松弛这条道路
            {
                dis[v]=dis[now]+t;
                if(!vis[v])
                {
                    vis[v]=1;
                    if(q.size())
                    {
                        if(dis[v]>dis[q.front()])
                            q.push_back(v);
                        else
                            q.push_front(v);
                    }
                    else
                        q.push_back(v);
                }
            }
        }
    }
    return dis[n];
}

int main()
{
    int T;
    scanf("%d",&T);//以后这种多少个case,你就写大写的T吧,不要再重名了,这种错误真的很难找
    while(T--)
    {
        cnt=0;
        memset(head,-1,sizeof(head));
        memset(Edge,0,sizeof(Edge));
        memset(w,0,sizeof(w));
        scanf("%d %d %d",&n,&m,&limit);
        for(int i=0;i<m;i++)
        {
            int u,v,t,c;
            scanf("%d %d %d %d",&u,&v,&c,&t);
            add_edge(u,v,c,t);
            add_edge(v,u,c,t);
            w[i].c=c,w[i].t=t;;
        }
        sort(w,w+m,cmp);
        int l=0,r=m-1,mid;
        while(l<=r)
        {
            mid=(l+r)/2;
        ll  temp=spfa(w[mid].c);//高度值
            if(temp!=INF&&temp<=limit)
            {
                l=mid+1;
            }
            else
                r=mid-1;
        }
        printf("%d\n",w[r].c);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值