• HDU Delay Constrained Maximum Capacity Path(最短路+二分)


    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.

    InputThe 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.
    OutputFor 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

    有两种限制条件

    对于限制最大容量的二分考虑即可

    剩下的SPFA 跑一下最短路 判断是否小于T

    这题居然良心不卡SPFA

    code:

    //
    #include<bits/stdc++.h>
    using namespace std;
    #define maxnn 100100
    int n,m,t;
    int T;
    int dis[maxnn];
    struct node
    {
        int en,nex,le,cost;
    }edge[maxnn];
    int las[maxnn],tot;
    int mark[maxnn];
    void add(int a,int b,int c,int d)
    {
        edge[++tot].en=b;
        edge[tot].nex=las[a];
        las[a]=tot;
        edge[tot].le=d;
        edge[tot].cost=c;
    }
    queue < int > Q;
     
    void spfa(int val)
    {
        for(int i=1;i<=n;i++) dis[i]=100000000,mark[i]=0;
        Q.push(1);
        dis[1]=0;
        mark[1]=1;
        while(Q.size())
        {
            int s=Q.front();
            Q.pop();
            mark[s]=0;
            for(int i=las[s];i;i=edge[i].nex)
            {
                int y=edge[i].en;
                
                if(edge[i].cost<val)continue;
                if(dis[y]>dis[s]+edge[i].le)
                {
                        dis[y]=dis[s]+edge[i].le;
                    if(!mark[y])
                    {
                        mark[y]=1;
                        Q.push(y);
                    }
                }
            }
        }
    }
    bool isok(int v)
    {
        spfa(v);
        return dis[n]>t? false: true;
    }
    int main()
    {
        cin>>T;
        int a,b,c,d;
        int l=0,r=0;
        while(T--)
        {
            for(int i=1;i<=tot;i++)
            {
                las[i]=0;
                edge[i].en=0;
                edge[i].nex=0;
                edge[i].le=0;
                edge[i].cost=0;
                
            }
            tot=0;
            l=0,r=0;
            scanf("%d%d%d",&n,&m,&t);
            for(int i=1;i<=m;i++)
            {
                cin>>a>>b>>c>>d;
                add(a,b,c,d);
                add(b,a,c,d);
                r=max(r,c);
            }
            while(l<=r)
            {
                int mid=(l+r)>>1;
                if(isok(mid))
                {
                    l=mid+1;
                }
                else
                r=mid-1;    
            }
            cout<<r<<endl;
        }
    }
    刀剑映出了战士的心。而我的心,漆黑且残破
  • 相关阅读:
    20190503-汉明距离
    20190501-编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串
    20190502-罗马数字转换为数字
    20190501-整数翻转
    20190426-选择排序算法
    Excel技巧—一个公式实现中英文翻译
    Excel技巧—两招轻松搞定汉字转拼音
    Excel基础—开始菜单之花式粘贴四
    Excel技巧—瞬间吸引眼球的WIFI图表
    Excel技巧—自动标记颜色条件格式的妙用
  • 原文地址:https://www.cnblogs.com/OIEREDSION/p/11266280.html
Copyright © 2020-2023  润新知