HDU-1839-二分下限+spfa

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;
}




全部评论

相关推荐

机智的豹子有点心碎:UU我还在找工作还没找到,一直在搜简历怎么改,总结了这些: 1.SEO:简历根据每一个岗位定制化:使用这个岗位中所描述的工作的词,它要求什么技能就把自己的技能描述成什么样子,把SEO用在自己身上(把我的简历和个人特质,当成一个热门产品来做 “搜索引擎优化”),让HR能用最低的门槛看到我 2."顺序:把岗位要求的技能跟经历放在简历的最开头、最显眼的位置" 3.包装:简历是一个最终交付说明书,只要最终学习成长做得到就可以,在合适的范围内自我吹捧(我这个人怎么能够在HR的角度被迅速的看懂和看到,减轻HR的工作压力) 4.每点加小标题​:用6~10字概括该段内容,便于面试官快速抓取信息。 5.避免空泛描述​:拒绝“培养了组织能力”等泛泛而谈,替换为具体行动和成果。 6."使用“三段式结构”​​:每段经历按“为什么做-做了什么-结果如何”展开: ​a) 为什么做​:痛点或目标(例如“品牌声量不足”) ​b) 做​了什么:方法论(例如“趋势洞察+竞品对标+人群细分”) ​c) 结果如何​:量化成果或影响(例如“推动客户投放20万预算”)" 7.量化成果​:用数字体现工作成效(如“整理500+份资料”“撰写2万字报告”)。 这些有的是我想去的岗的,如果对你有用的话按需修改就好~加油,早日上岸!
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务