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
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.
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.
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.
#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+二分)的更多相关文章
- hdu 1839 Delay Constrained Maximum Capacity Path 二分/最短路
Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...
- hdu 1839 Delay Constrained Maximum Capacity Path
最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio&g ...
- hdu 1874 畅通工程续(模板题 spfa floyd)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874 spfa 模板 #include<iostream> #include<stdio ...
- 【启发式搜索】Codechef March Cook-Off 2018. Maximum Tree Path
有点像计蒜之道里的 京东的物流路径 题目描述 给定一棵 N 个节点的树,每个节点有一个正整数权值.记节点 i 的权值为 Ai.考虑节点 u 和 v 之间的一条简单路径,记 dist(u, v) 为其长 ...
- Codechef March Cook-Off 2018. Maximum Tree Path
目录 题意 解析 AC_code @(Codechef March Cook-Off 2018. Maximum Tree Path) 题意 给你一颗\(n(1e5)\)个点有边权有点权的树,\(Mi ...
- HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...
- HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和)
HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 1588 Gauss Fibonacci 题意: g(i)=k*i+b;i为变量. 给出 ...
- HDU 1839
http://acm.hdu.edu.cn/showproblem.php?pid=1839 题意:从1到n,要求时间小于等于T到达.每条边有一个容量,问最多能运多少货物. 分析:最多能运的货物取决于 ...
- 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 ...
随机推荐
- java实体类的属性名首字母不能大写,不然el表达式无法取值
摘要:Java命名规范中,实体类属性名以小写字母开头,但并没有说不能以大写字母开头,然而事实告诉我,大写真不行 https://www.cnblogs.com/jnhs/p/10025757.html
- JSP内置对象解析
out对象:(PrintWriter类的实例) 用来向客户端输出信息,除了输出各种信息外还负责对缓冲区进行管理: 主要方法: print / println void 输出数据 newLine() v ...
- LINNX查看当前登录的用户
W w命令主要是查看当前登录的用户,这个命令相对来说比较简单.我们来看一下截图. 在上面这个截图里面呢,第一列user,代表登录的用户,第二列,tty代表用户登录的终端号,因为在linux中并不是只有 ...
- 【洛谷】P1590 失踪的7
P1590 失踪的7 题目描述 远古的Pascal人也使用阿拉伯数字来进行计数,但是他们又不喜欢使用7,因为他们认为7是一个不吉祥的数字,所以Pascal数字8其实表示的是自然数中的7,18表示的是自 ...
- Ubuntu上更换163源 - Mars Loo的博客
转载*请注明原始出处:http://blog.csdn.net/a464057216/article/details/50865895 先备份源/etc/apt/sources.list为source ...
- web前端学习(二)html学习笔记部分(6)--fileAPI
1.2.18 html5 File API的应用 1.2.18.1 实现可选择列表 通过为列表项增加一个选择框,进而实现列表的多选和对选择文件的删除.同时,在选择.取消选择时实现操作栏的切换. 1. ...
- Serializable 可串行化接口
Serializable 可串行化接口 定义一个User类,实现Serializable接口: package com.monkey1025; import java.io.Serializable; ...
- NOIP模拟 17.8.16
NOIP模拟17.8.16 A 债务文件名 输入文件 输出文件 时间限制 空间限制debt.pas/c/cpp debt.in debt.out 1s 128MB[题目描述]小 G 有一群好朋友,他们 ...
- SpringBoot Cloud eureka 注册中心
SpringBoot Cloud是什么 Spring Cloud是一个分布式的整体解决方案. Spring Cloud 为开发者提供了在分布式系统(配置管理,服务发现,熔断,路由,微代理,控制总线,一 ...
- 启动Jmeter录制代理进行录制,报 jmeter.protocol.http.proxy.ProxyControl
使用jmeter代理录制Http请求时,启动HTTP(S) Test Script Recorder报jmeter.protocol.http.proxy.ProxyControl, 日志为: 201 ...