hdu 1839(二分+最短路)
来源:互联网 发布:生活方式 知乎 编辑:程序博客网 时间:2024/05/22 12:45
Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
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
22 1 101 2 13 104 4 201 2 1000 152 4 999 61 3 100 153 4 99 4
Sample Output
1399题意:有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。一条路径的运输容量取决与这条路径中的运输容量最小的那条边。解题思路:二分+最短路。二分枚举的是最大容量,然后用spfa判断是否最短路满足小于t。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int N = 100005;const int M = 500005;const int inf = 0x3f3f3f3f;struct Edge{int to,next;int c,d;}edge[M<<1];int n,m,t,cnt,cap[N],pre[N],dis[N];bool inq[N];void addedge(int u,int v,int c,int d){edge[cnt].to = v;edge[cnt].c = c;edge[cnt].d = d;edge[cnt].next = pre[u];pre[u] = cnt++;}bool spfa(int limit){queue<int> q;memset(inq,false,sizeof(inq));memset(dis,inf,sizeof(dis));dis[1] = 0;q.push(1);inq[1] = true;while(!q.empty()){int u = q.front();inq[u] = false;q.pop();for(int i = pre[u]; i != -1; i = edge[i].next){if(edge[i].c < limit) continue;int v = edge[i].to;if(dis[v] > dis[u] + edge[i].d){dis[v] = dis[u] + edge[i].d;if(inq[v] == false){inq[v] = true;q.push(v);}}}}return dis[n] <= t;}int main(){int cas,a,b,c,d;scanf("%d",&cas);while(cas--){scanf("%d%d%d",&n,&m,&t);cnt = 0;memset(pre,-1,sizeof(pre));for(int i = 1; i <= m; i++){scanf("%d%d%d%d",&a,&b,&c,&d);addedge(a,b,c,d);addedge(b,a,c,d);cap[i] = c;}sort(cap+1,cap+1+m);int l = 1,r = m,mid,ans;while(l <= r){mid = (l + r) >> 1;if(spfa(cap[mid])){ans = cap[mid];l = mid + 1;}else r = mid - 1;}printf("%d\n",ans);}return 0;}
0 0
- hdu 1839(二分+最短路)
- hdu 1839(二分+最短路)
- hdu 1839 二分搜索+dijkstra最短路
- hdu 2962(最短路+二分)
- hdu 2962 Trucking(二分+最短路)
- hdu 2962(二分答案+最短路)
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)
- HDU-1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- 【HDU】1839 Delay Constrained Maximum Capacity Path 二分+最短路
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+最短路
- HDU 1839 Delay Constrained Maximum Capacity Path (二分最短路)
- HDU 1839 Delay Constrained 带限制最短路:二分下限
- hdu 2962 Trucking (最短路之SPFA算法 + 二分)
- hdu 2363(限制最短路 二分+枚举+最短路)
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)
- linux系统644、755、777权限详解
- 学习排序算法2--插入排序
- android webview数据交互
- 关于在android中,如何一步到位,全局替换控件样式的一些看法
- 经验总结 2016年安徽省程序设计竞赛总结
- hdu 1839(二分+最短路)
- 可重入锁(ReentrantLock)
- Bootstrap 响应式实用工具——visible-xs、visible-sm、hidden-xs、hidden-sm等
- ORL Face Database 人脸识别数据集
- Android同步类:Mutex和Condition的使用方式
- Servlet的运行过程
- CentOS6网卡静态IP设置
- 2016.5.21初中部模拟赛总结
- javascript垃圾回收