hdu 1839 Delay Constrained Maximum Capacity Path 二分+最短路

14 篇文章 0 订阅
13 篇文章 0 订阅

题目链接:

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

题意:

有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。
他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。
一条路径的运输容量取决与这条路径中的运输容量最小的那条边。

题解:

二分cap,最短路判断

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int n,m,t;
ll c[maxn];

struct node{
    ll v,c,d;
    node(ll v=0,ll c=0,ll d=0) : v(v),c(c),d(d) {}
};
vector<node> E[maxn];

int inq[maxn],td[maxn];

ll check(ll c){
    for(int i=0; i<=n; i++) inq[i] = 0;
    for(int i=0; i<=n; i++) td[i] = INF;
    queue<int> q;
    q.push(1),td[1]=0,inq[1]=1;

    while(!q.empty()){
        int now = q.front();
        q.pop(),inq[now]=0;
        for(int i=0; i<(int)E[now].size(); i++){
            node e = E[now][i];
            ll v = e.v, cc = e.c, d = e.d;
            if(td[v] > td[now]+d && cc >= c){
                td[v] = td[now]+d;
                if(inq[v]) continue;
                inq[v] = 1;
                q.push(v);
            }
        }
    }

    return td[n];
}

int main(){
    int T = read();
    while(T--){
        scanf("%d%d%d",&n,&m,&t);
        for(int i=0; i<=n; i++) E[i].clear();
        MS(c);
        for(int i=0; i<m; i++){
            ll u,v,d; scanf("%I64d%I64d%I64d%I64d",&u,&v,&c[i],&d);
            E[u].push_back(node{v,c[i],d});
            E[v].push_back(node{u,c[i],d});
        }

        sort(c,c+m);

        int l=0,r=m-1,ans;
        while(l<=r){
            int mid = (l+r)/2;
            int tmp = c[mid];
            if(check(tmp) <= t){
                ans = tmp;
                l = mid+1;
            }else{
                r = mid-1;
            }
        }
        cout << ans << endl;
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值