Delay Constrained Maximum Capacity Path

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 544    Accepted Submission(s): 192

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
 

题目:给m条管道,每条管道有可运输的最大容量和消耗的时间c,t

现在有东西要从1运输到n,必须在时间T内完成,求符合条件的可运输的最大容量

分析:对于所给的m条管道的最大容量,进行排序,然后二分容量求从1到n的最短时间即可

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=10000+10;
int s[MAX*5],n,m,t;
int size,head[MAX],dist[MAX];
bool mark[MAX];
typedef pair<int,int>mp; struct Edge{
int v,c,t,next;
Edge(){}
Edge(int &V,int &C,int &T,int NEXT):v(V),c(C),t(T),next(NEXT){}
}edge[MAX*5*2]; inline void Init(int num){
memset(head,-1,sizeof(int)*(num+2));
size=0;
} inline void InsertEdge(int u,int v,int &c,int &t){
edge[size]=Edge(v,c,t,head[u]);//头插法
head[u]=size++;
} inline bool Dijkstra(int s,int t,int c,int T){
for(int i=1;i<=n;++i)mark[i]=false,dist[i]=INF;
dist[s]=0,mark[s]=true;
priority_queue< mp,vector<mp>,greater<mp> >q;
mp oq;
q.push(mp(0,s));
while(!q.empty()){
oq=q.top();
q.pop();
if(oq.first>T)return false;
if(oq.second == t)return dist[t];//dist[t]<=T;
mark[oq.second]=true;
for(int i=head[oq.second];i != -1;i=edge[i].next){
int v=edge[i].v;
if(mark[v] || edge[i].c<c)continue;
if(oq.first+edge[i].t<dist[v]){
dist[v]=oq.first+edge[i].t;
q.push(mp(dist[v],v));
}
}
}
return false;//无法到达t
} int main(){
int num,u,v,c,T;
cin>>num;
while(num--){
scanf("%d%d%d",&n,&m,&t);
Init(n);
for(int i=0;i<m;++i){
scanf("%d%d%d%d",&u,&v,&c,&T);
InsertEdge(u,v,c,T);
InsertEdge(v,u,c,T);
s[i]=c;
}
sort(s,s+m);
int left=0,right=0,mid;
for(int i=1;i<m;++i)if(s[i] != s[i-1])s[++right]=s[i];
while(left<=right){
mid=left+right>>1;
if(Dijkstra(1,n,s[mid],t))left=mid+1;
else right=mid-1;
}
printf("%d\n",s[right]);
}
return 0;
}

hdu1839之二分+邻接表+Dijkstra+队列优化的更多相关文章

  1. POJ 1511 - Invitation Cards 邻接表 Dijkstra堆优化

    昨天的题太水了,堆优化跑的不爽,今天换了一个题,1000000个点,1000000条边= = 试一试邻接表 写的过程中遇到了一些问题,由于习惯于把数据结构封装在 struct 里,结果 int [10 ...

  2. HDU 2544 最短路(floyd+bellman-ford+spfa+dijkstra队列优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 题目大意:找点1到点n的最短路(无向图) 练一下最短路... dijkstra+队列优化: #i ...

  3. ACM/ICPC 之 数据结构-邻接表+DP+队列+拓扑排序(TSH OJ-旅行商TSP)

    做这道题感觉异常激动,因为在下第一次接触拓扑排序啊= =,而且看了看解释,猛然发现此题可以用DP优化,然后一次A掉所有样例,整个人激动坏了,哇咔咔咔咔咔咔咔~ 咔咔~哎呀,笑岔了- -|| 旅行商(T ...

  4. USACO 2008 January Silver Telephone Lines /// 二分最短路 邻接表dijkstra oj22924

    题目大意: 一共有N (1 ≤ N ≤ 1,000)个电线杆,有P P (1 ≤ P ≤ 10,000)对电线杆是可以连接的, 用几条线连接在一起的电线杆之间都可相互通信,现在想要使得电线杆1和电线杆 ...

  5. POJ-2387Til the Cows Come Home,最短路坑题,dijkstra+队列优化

    Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K       http://poj.org/problem?id=238 ...

  6. 确定比赛名次(map+邻接表 邻接表 拓扑结构 队列+邻接表)

    确定比赛名次 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  7. POJ - 3037-Skiing(邻接表+Dijkstra)

    Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie ...

  8. bfs 邻接表(需要优化 可能会RE *【模板】)

    //---基于邻接表的bfs #include <stdio.h> #include <string.h> #include <iostream> #include ...

  9. 08-图8 How Long Does It Take(25 分)邻接表和队列

    Given the relations of all the activities of a project, you are supposed to find the earliest comple ...

随机推荐

  1. c++ 联合体

    联合体分配的内存大小是成员变量中最大变量的大小 联合体的成员变量共享内存 小段模式(X86就是) 低位数据存在低地址单元 大端模式                     高位字节存在低地址单元

  2. Portal技术综述

    从上世纪八十年代起,随着个人计算机(PC)的发展,企事业单位逐步建立起计算机应用系统来处理传统事务.从简单的单机应用逐步发展到局域网系统,进而建立跨地区垮国家的广域网系统.从单纯的以科学计算和数据管理 ...

  3. unity 与 android 协调工作 注意事项

    原地址:http://blog.csdn.net/u012085988/article/details/17436191 1.unity调android函数 AndroidJavaClass jc = ...

  4. sql replace into 与 insert into

    sql replace into用法详细说明 REPLACE的运行与INSERT很相似.只有一点例外,假如表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有相同的值,则 ...

  5. routes.IgnoreRoute("{resource}.axd/{*pathInfo}")作用

    {resource}.axd 表示后缀名为.axd所有资源 如webresource.axd{*pathInfo} 表示所有路径 作用:使路由系统忽略处理ASP.NET的Web资源文件(WebReso ...

  6. 深入WSGI,并按样例实现一个

    感觉WSGI确实和SERVLET相似,为PYTHON提供了运行和管理环境.WSGI服务器和PYTHON的WEB框架一起,实现WEB响应. 步骤: 首先,服务器启动并加载一个由Web框架/应用提供的可调 ...

  7. [Gauss]POJ1830 开关问题

    中文题 题意不多说 这题乍一看 就是求个自由未知量个数 相当简单 其实呢 其中要注意的细节还是很多的: 1.光求了自由未知量个数 还不够 ∵求的是可行方案的总数  因此 答案是 2^(自由未知量个数) ...

  8. SQL Server 行列转换

    /* 标题:普通行列转换(version 2.0) 作者:范中磊 说明:普通行列转换(version 1.0)仅针对sql server 2000提供静态和动态写法,version 2.0增加sql ...

  9. 一个灵巧的Delphi多播实事件现方案

    一个灵巧的Delphi多播实现方案.必须是支持泛型的Delphi版本.也就是Delphi2009以后.强烈建议用DelphiXE. 用法就是例如写一个Class指定一个Event,触发的时候会通知多个 ...

  10. Android自定义属性时format选项可以取用的值

    1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name="名称"> <attr format=" ...