zoukankan      html  css  js  c++  java
  • 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;
        }
    }
    刀剑映出了战士的心。而我的心,漆黑且残破
  • 相关阅读:
    O(1)时间复杂度实现入栈、出栈、获得栈中最小元素、获得栈中最大元素(转)
    北京网选赛第二题(最大仰望角度)
    最小圆覆盖(随机增量法&模拟退火法)
    模拟退火算法A Star not a Tree?(poj2420)
    模拟退火算法(run away poj1379)
    模拟退火算法(西安网选赛hdu5017)
    最小费用流判负环消圈算法(poj2175)
    中国邮递员问题(一)
    破坏行动问题
    进化树问题
  • 原文地址:https://www.cnblogs.com/OIEREDSION/p/11266280.html
Copyright © 2011-2022 走看看