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


    Delay Constrained Maximum Capacity Path

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

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

    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

    HINT

    题意

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

    题解:

    二分cap,然后直接最短路判断就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 500001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x7fffffff;
    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;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    int n,m,t;
    struct node
    {
        int x;
        ll y;
        int z;
    };
    bool cmp(ll a,ll b)
    {
        return a>b;
    }
    vector<node> e[maxn];
    ll c[maxn];
    int inq[maxn];
    int d[maxn];
    int solve(int x)
    {
        for(int i=0;i<=n;i++)
            d[i]=inf;
        d[1]=0;
        queue<int> q;
        q.push(1);
        while(!q.empty())
        {
            int v=q.front();
            q.pop();
            for(int i=0;i<e[v].size();i++)
            {
                if(e[v][i].y>=x)
                {
                    if(d[e[v][i].x]>d[v]+e[v][i].z)
                    {
                        d[e[v][i].x]=d[v]+e[v][i].z;
                        q.push(e[v][i].x);
                    }
                }
            }
        }
        return d[n];
    }
    int main()
    {
        //test;
        int T=read();
        while(T--)
        {
            n=read(),m=read(),t=read();
            for(int i=0;i<maxn;i++)
                e[i].clear();
            memset(c,0,sizeof(c));
            for(int i=0;i<m;i++)
            {
                int a=read(),b=read();
                c[i]=read();
                int d=read();
                e[a].push_back((node){b,c[i],d});
                e[b].push_back((node){a,c[i],d});
            }
            sort(c,c+m,cmp);
            int l=0,r=m-1,mid;
            while(l<r)
            {
                mid=(l+r)/2;
                int tmp=c[mid];
                if(solve(tmp)>t)
                    l=mid+1;
                else
                    r=mid;
            }
            cout<<c[l]<<endl;
        }
    }

     

  • 相关阅读:
    哈希表
    跳表
    哈夫曼之谜
    选择树、判定树和查找树

    将gbk字符串转换成utf-8,存储到注册表中后,再次从注册表读取转换成gbk,有问题!!!
    函数内部还是不要使用 strtok()
    没想到: System.out.println(n1 == f1 ? n1 : f1);
    在不同DPI屏幕环境下,让图标显示的尺寸保持不变,使用 LoadImage() 加载图标
    在多线程中显示模态窗口,出现异常现象
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4568939.html
Copyright © 2020-2023  润新知