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 ...
随机推荐
- 基于jQuery实现页面滚动时顶部导航显示隐藏效果
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...
- Linux预习
目录 linux系统和unix系统的简介 linux系统和unix系统的简介 unix是什么:和widows一样 特点:多用户,多任务 同一时刻,多用户同时执行多项程序,互不干扰 GNU项目 就是一个 ...
- day37 01-上次课内容回顾
- ubuntu16.04上在使用搜狗输入法时,按shift不能正常切换中英文
问题描述: ubuntu16.04上在使用搜狗输入法时,不知道把什么组合键给错按了,导致了按shift不能正常切换中英文,这是一件很烦恼的事儿! 解决步骤: 1,终端输入打开: fcitx-confi ...
- 【python之路19】文件操作
一.打开文件 文件句柄 = open('文件路径', '模式') 打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作. 打开文件的模式有: r ...
- 用Direct2D和DWM来做简单的动画效果
原文:用Direct2D和DWM来做简单的动画效果 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sunnyloves/article/detail ...
- day38 18-Spring的XML和注解的结合使用
什么情况下使用XML,什么情况下使用注解?又有XML,又有注解,开发的时候使用哪种? XML:结构清晰,配置麻烦. 注解:简单, 它俩的结合点在属性注入上. 两种方式结合:一般使用XML注册Bean, ...
- 2018-5-4-WPF-获得触摸精度和触摸点
title author date CreateTime categories WPF 获得触摸精度和触摸点 lindexi 2018-05-04 21:11:51 +0800 2018-5-4 21 ...
- Spring表达式语言:SpEl
概念: 是一个支持运行时查询和操作的对象图的强大的表达式语言. 语法类似于EL:SpEl使用#{ ...}作为定界符,所有在大括号中的 字符都将被认为是SpEl SpEl为bean的属性进行动态赋值提 ...
- jquery 浏览器缓存网页
头部:<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate&q ...