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. EL表达式如何读取一个string型的list 一个单纯的的字符串list

    <c:forEach begin="0" end="${columnList.size()-1}" var="i"> ${ co ...

  2. mysql5 msi安装版

    有安装版为啥要用解压版? 搞不懂为啥大佬们都喜欢解压版? http://ftp.ntu.edu.tw/MySQL/Downloads/MySQLInstaller/mysql-installer-co ...

  3. day18 9.转账汇款案例(1)

  4. Leetcode43. Multiply Strings字符串相乘(大数相乘)

    给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式. 示例 1: 输入: num1 = "2", num ...

  5. 怎么让一个不定宽高的div垂直水平居中?

    方法一:使用CSS3 transform 父盒子设置:position:relative; div设置:position:absolute;transform:translate(-50%,-50%) ...

  6. 获取电脑名和Ip

    private string  GetHostNameAndIP( bool  isv4Orv6)        {            string HostName = Dns.GetHostN ...

  7. Django项目:CRM(客户关系管理系统)--11--04PerfectCRM实现King_admin注册功能03

    #base_admin.py #Django admin 注册功能的形式 # sites = { # 'crm':{ # 'customers':CustomerAdmin, # 'customerf ...

  8. Linux 7.X 网络配置

    Linux 7.X 网络配置 环境: 笔记本中安装了虚拟机,在虚拟机中安装了Redhat 7.4版本的操作系统,现配置该操作系统网络.(IP.网关等) 相关指令如下: # nmcli connecti ...

  9. python mooc 3维可视化<第一周第一单元>

    基本含义 数据->图像 分类 重点关注空间数据的可视化 方法 二维标量数据场 三维标量数据场 二位标量数据场 颜色映射法 等值线法 立体图法 层次分割法 三维标量数据场 面绘制法 体绘制法 展示 ...

  10. php文件上传$_FILES数组格式

    <form action="" enctype="multipart/form-data" method="post"> < ...