博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)
阅读量:5318 次
发布时间:2019-06-14

本文共 4175 字,大约阅读时间需要 13 分钟。

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之内,在这个前提之下,要让这条路径的运输容量尽可能地大。每条路径的运输容量取决与这条路径中的运输容量最小的那条边。
 
使用二分枚举,因为资源越多,能走的路就越少,因此使用二分从大到小排序之后枚举。
 
附上代码:
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #define INF 0x3f3f3f3f 7 #define M 50005 8 #define N 10005 9 using namespace std; 10 11 int tol,n,m,t,limit; 12 struct Edge 13 { 14 int form,to,val,time; 15 int next; 16 } edge[M*2]; 17 18 int head[M*2],dis[N],r[M]; 19 bool vis[N]; 20 21 bool cmp(int a,int b) 22 { 23 return a>b; 24 } 25 26 void init() 27 { 28 tol=0; 29 memset(head,-1,sizeof(head)); 30 } 31 32 void addEdge(int u,int v,int val,int time) ///邻接表 33 { 34 edge[tol].form=u; 35 edge[tol].to=v; 36 edge[tol].val=val; 37 edge[tol].time=time; 38 edge[tol].next=head[u]; 39 head[u]=tol++; 40 edge[tol].form=v; 41 edge[tol].to=u; 42 edge[tol].val=val; 43 edge[tol].time=time; 44 edge[tol].next=head[v]; 45 head[v]=tol++; 46 } 47 48 void getmap() 49 { 50 scanf("%d%d%d",&n,&m,&t); 51 int a,b,c,d; 52 for(int i=0; i
q; 67 q.push(1); 68 dis[1]=0; 69 vis[1]=true; 70 while(!q.empty()) 71 { 72 int u=q.front(); 73 q.pop(); 74 vis[u]=false; 75 for(int i=head[u]; i!=-1; i=edge[i].next) 76 { 77 int v=edge[i].to; 78 if(edge[i].val>=limit) 79 if(dis[v]>dis[u]+edge[i].time) 80 { 81 dis[v]=dis[u]+edge[i].time; 82 if(!vis[v]) 83 { 84 vis[v]=true; 85 q.push(v); 86 } 87 } 88 } 89 } 90 return dis[n]; 91 } 92 93 94 95 void search() 96 { 97 int left=0,right=m-1,mid; 98 while(left
t)104 left=mid+1;105 else106 right=mid;107 }108 printf("%d\n",r[left]);109 }110 111 int main()112 {113 int T;114 scanf("%d",&T);115 while(T--)116 {117 init();118 getmap();119 search();120 }121 return 0;122 }

 

转载于:https://www.cnblogs.com/pshw/p/5749772.html

你可能感兴趣的文章
《数据分析实战》--第三章 python实现
查看>>
实验八 接口与实现接口的类
查看>>
PostgreSQL 保留关键字添加方法之一,不带参数的函数
查看>>
赛前热手 (天梯赛暴力题)
查看>>
Uva(10330)
查看>>
vlan学习
查看>>
【转贴】SAP HANA内存数据库详解
查看>>
两种应该掌握的排序方法--------1.shell Sort
查看>>
vuejs动态组件给子组件传递数据
查看>>
杭电2065(递推)红色病毒
查看>>
js 获取视频的第一帧
查看>>
各种正则验证
查看>>
观察者模式(Observer)
查看>>
python中numpy.r_和numpy.c_
查看>>
WPF简单模拟QQ登录背景动画
查看>>
bzoj 2038 小Z的袜子
查看>>
egret3D与2D混合开发,画布尺寸不一致的问题
查看>>
freebsd 实现 tab 命令 补全 命令 提示
查看>>
struts1和struts2的区别
查看>>
函数之匿名函数
查看>>