HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典

Delay Constrained Maximum Capacity Path

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 1314    Accepted Submission(s): 418

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

Author

Mugurel Ionut Andreica

Source

Politehnica University of Bucharest Local Team Contest 2007

题意:有n个地点,m条边,有一种矿物在1,矿物加工场在n,假设从1到n运送矿物的时间大于T的话,矿物就会分解,要求运送尽可能多的矿物到加工厂。

#include<stdio.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 10005;
struct EDG
{
    int u,v,c,t;
    friend bool operator<(const EDG &a,const EDG &b)
    {
        return a.c<b.c;
    }
};

EDG edg[5*N];
vector<EDG>mapt[N];
int n,T,minTim[N];

bool spfaTim(int ans)
{
    queue<int>q;
    int s,k;
    bool inq[N]={0};
    for(int i=1;i<=n;i++)
    minTim[i]=-1;
    minTim[1]=T; q.push(1);
    while(!q.empty())
    {
        s=q.front(); q.pop();
        inq[s]=0;
        k=mapt[s].size();
        for(int i=0;i<k;i++)
        if(mapt[s][i].c>=ans)
        {
            int v=mapt[s][i].v;
            if(minTim[v]<minTim[s]-mapt[s][i].t)
            {
                if(v==n)
                 return true;
                minTim[v]=minTim[s]-mapt[s][i].t;
                if(!inq[v])
                inq[v]=true,q.push(v);
            }
        }
    }
    return false;
}

int main()
{
    int cas,m,ans;
    EDG ss;
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d%d%d",&n,&m,&T);
        for(int i=1;i<=n;i++)
        mapt[i].clear();
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d%d",&edg[i].u,&edg[i].v,&edg[i].c,&edg[i].t);
            ss.c=edg[i].c; ss.t=edg[i].t;
            ss.v=edg[i].v; mapt[edg[i].u].push_back(ss);
            ss.v=edg[i].u; mapt[edg[i].v].push_back(ss);
        }
        sort(edg+1,edg+1+m);
        int l=1,r=m,mid;
        ans=0;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(spfaTim(edg[mid].c))
             {
                 ans=edg[mid].c; l=mid+1;
             }
             else r=mid-1;
        }
        printf("%d\n",ans);
    }
}
时间: 2024-10-25 17:42:18

HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典的相关文章

hdu1839Delay Constrained Maximum Capacity Path 二分+最短路

//一个无向图,两点之间的流量为c,两点花的时间为t //问从起点到终点n之间时间小于等于T且只走一条路径能够运输的最大流量为多少 //二分流量,小于这个流量的路径不走,求其时间是否小于等于T得到答案 #include<cstdio> #include<cstring> #include<iostream> #include<queue> using namespace std ; const int maxn = 10010 ; const int max

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

题目地址:HDU 1839 我去..原来这题这么简单...网络流中这种二分建图的方式做了一大堆了..这种题还能难倒我吗...白天一直没怎么看懂题,对题意懵懵懂懂的...晚上好好看了看题,这不就是网络流中练的最多的那种二分建图模型吗....只是把网络流算法改成最短路就行了..但是两个地方手残了没能在实验室当场A掉..sad... 这题就是二分最小容量,对满足容量的加边,对时间求最短路.如果最短时间比规定时间少的话就可以继续增加容量,直到不能增加为止. 代码如下: #include <iostrea

复习图---Delay Constrained Maximum Capacity Path(SPFA+二分)

Delay Constrained Maximum Capacity Path Time Limit:10000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Description Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with

hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)

Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1790    Accepted Submission(s): 577 Problem Description Consider an undirected graph with N vertices, nu

HDU1839_Delay Constrained Maximum Capacity Path(最短路+二分)

解题报告 http://blog.csdn.net/juncoder/article/details/38349019 题目传送门 题意: 有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点.走每条边的运输容量为C,运送时间为D. 他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大. 一条路径的运输容量取决与这条路径中的运输容量最小的那条边. 思路: 二分容量建图,spfa判时间是否符合条件 #incl

【HDU 1839】 Delay Constrained Maximum Capacity Path(二分+最短路)

[HDU 1839] Delay Constrained Maximum Capacity Path(二分+最短路) Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1515    Accepted Submission(s): 481 Problem

hdu 1839 Delay Constrained Maximum Capacity Path

最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio> #include<vector> #include<cstring> #include<queue> #include<map> #include<algorithm> using namespace std; const int maxn =

POJ 3662 Telephone Lines(二分答案+SPFA)

[题目链接] http://poj.org/problem?id=3662 [题目大意] 给出点,给出两点之间连线的长度,有k次免费连线, 要求从起点连到终点,所用的费用为免费连线外的最长的长度. 求最小费用. [题解] 二分答案,对于大于二分答案的边权置为1,小于等于的置为0, 则最短路就是超出二分答案的线数,如果小于等于k,则答案是合法的 [代码] #include <cstdio> #include <cstring> using namespace std; const i

bzoj1614: [Usaco2007 Jan]Telephone Lines架设电话线(二分答案 + spfa)

原题链接 题目描述:FarmerJohn打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用.FJ的农场周围分布着N(1<=N<=1,000)根按1..N顺次编号的废弃的电话线杆,任意两根电话线杆间都没有电话线相连.一共P(1<=P<=10,000)对电话线杆间可以拉电话线,其余的那些由于隔得太远而无法被连接.第i对电话线杆的两个端点分别为A_i.B_i,它们间的距离为L_i(1<=L_i<=1,000,000).数