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, 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
 
题意:有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。每条路径的运输容量取决与这条路径中的运输容量最小的那条边。
 
使用二分枚举,因为资源越多,能走的路就越少,因此使用二分从大到小排序之后枚举。
 
附上代码:
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
#define M 50005
#define N 10005
using namespace std; int tol,n,m,t,limit;
struct Edge
{
int form,to,val,time;
int next;
} edge[M*]; int head[M*],dis[N],r[M];
bool vis[N]; bool cmp(int a,int b)
{
return a>b;
} void init()
{
tol=;
memset(head,-,sizeof(head));
} void addEdge(int u,int v,int val,int time) ///邻接表
{
edge[tol].form=u;
edge[tol].to=v;
edge[tol].val=val;
edge[tol].time=time;
edge[tol].next=head[u];
head[u]=tol++;
edge[tol].form=v;
edge[tol].to=u;
edge[tol].val=val;
edge[tol].time=time;
edge[tol].next=head[v];
head[v]=tol++;
} void getmap()
{
scanf("%d%d%d",&n,&m,&t);
int a,b,c,d;
for(int i=; i<m; i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
r[i]=c;
addEdge(a,b,c,d);
}
sort(r,r+m,cmp); ///从大到小排序 } int spfa() ///求最短时间
{
memset(dis,INF,sizeof(dis));
memset(vis,false,sizeof(vis));
queue<int>q;
q.push();
dis[]=;
vis[]=true;
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=false;
for(int i=head[u]; i!=-; i=edge[i].next)
{
int v=edge[i].to;
if(edge[i].val>=limit)
if(dis[v]>dis[u]+edge[i].time)
{
dis[v]=dis[u]+edge[i].time;
if(!vis[v])
{
vis[v]=true;
q.push(v);
}
}
}
}
return dis[n];
} void search()
{
int left=,right=m-,mid;
while(left<right) ///二分
{
mid=(left+right)/;
limit=r[mid];
int tmp=spfa();
if(tmp==INF||tmp>t)
left=mid+;
else
right=mid;
}
printf("%d\n",r[left]);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
init();
getmap();
search();
}
return ;
}

hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)的更多相关文章

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

    Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...

  2. hdu 1839 Delay Constrained Maximum Capacity Path

    最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio&g ...

  3. hdu 1874 畅通工程续(模板题 spfa floyd)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874 spfa 模板 #include<iostream> #include<stdio ...

  4. 【启发式搜索】Codechef March Cook-Off 2018. Maximum Tree Path

    有点像计蒜之道里的 京东的物流路径 题目描述 给定一棵 N 个节点的树,每个节点有一个正整数权值.记节点 i 的权值为 Ai.考虑节点 u 和 v 之间的一条简单路径,记 dist(u, v) 为其长 ...

  5. Codechef March Cook-Off 2018. Maximum Tree Path

    目录 题意 解析 AC_code @(Codechef March Cook-Off 2018. Maximum Tree Path) 题意 给你一颗\(n(1e5)\)个点有边权有点权的树,\(Mi ...

  6. HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)

    HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...

  7. HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和)

    HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 1588 Gauss Fibonacci 题意:  g(i)=k*i+b;i为变量.  给出 ...

  8. HDU 1839

    http://acm.hdu.edu.cn/showproblem.php?pid=1839 题意:从1到n,要求时间小于等于T到达.每条边有一个容量,问最多能运多少货物. 分析:最多能运的货物取决于 ...

  9. HDU ACM 1224 Free DIY Tour (SPFA)

    Free DIY Tour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. java list转换json格式

    /** * 处理返回值(转换json格式和补零) * * @param resultDto5List * @param dateList * @return */ private JSONObject ...

  2. CentOS 6.8 Java 环境搭建

      1.搜索 Java 1.7 64 2.下载 文件 3.Xshell 安装lrzsz 4.选择路径 5.使用 rz 命令选择上传 6.打开 /etc/profile vim /etc/profile ...

  3. Codeforces Round #436 (Div. 2) 题解864A 864B 864C 864D 864E 864F

    A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. 洛谷P1970 [NOIP2013提高组Day2T2] 花匠

    P1970 花匠 题目描述 花匠栋栋种了一排花,每株花都有自己的高度.花儿越长越大,也越来越挤.栋栋决定 把这排中的一部分花移走,将剩下的留在原地,使得剩下的花能有空间长大,同时,栋栋希 望剩下的花排 ...

  5. python-None

    今天偶然间,有人问了一个问题,项目中出现了一个这样的错误. 看到后,就想到是前后数据类型不一致.当时他定义了一些默认初始值为None(刚接触python代码,之前是c,java),然后就后边出现了这样 ...

  6. Linux操作系统各版本ISO镜像下载(包括oracle linux\redhat\centos\u

    Linux操作系统各版本ISO镜像下载(包括oracle linux\redhat\centos\ubuntu\debian等) 1.Oracle Linux(下载地址) (1)OracleLinux ...

  7. Mybatis - plus 配置与运用

    Mybatis - plus mybatis-plus 官方文档  1.配置 引入对应的文件包,spring boot + mybatis 需添加依赖文件如下: <dependencies> ...

  8. vue中is的作用和用法

    回顾vue官方文档的过程中发现了is这个特性,虽然以我的写代码风格实在用不上,不过还是记录一下这个知识点 is的作用 <ul> <li></li> <li&g ...

  9. 【水滴石穿】rnTest

    其实就是一个小的demo,不过代码分的挺精巧的 先放地址:https://github.com/linchengzzz/rnTest 来看看效果 确实没有什么可以说的,不过代码部分还行 先入口文件 / ...

  10. java时间还在用date和calender?换LocalDateTime吧!

    java在时间计算上一直为人所诟病,在社区强烈反应下,java8推出了线程安全.简易.高可靠的时间包.并且数据库中也支持LocalDateTime类型,所以在数据存储时候使时间变得简单. LocalD ...