HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典
来源:互联网 发布:java框架书籍知乎 编辑:程序博客网 时间:2024/06/16 23:47
Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1314 Accepted Submission(s): 418
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
Author
Mugurel Ionut Andreica
Source
Politehnica University of Bucharest Local Team Contest 2007
题意:有n个地点,m条边,有一种矿物在1,矿物加工场在n,假设从1到n运送矿物的时间大于T的话,矿物就会分解,要求运送尽可能多的矿物到加工厂。
#include<stdio.h>#include<queue>#include<algorithm>#include<vector>using namespace std;const int N = 10005;struct EDG{ int u,v,c,t; friend bool operator<(const EDG &a,const EDG &b) { return a.c<b.c; }};EDG edg[5*N];vector<EDG>mapt[N];int n,T,minTim[N];bool spfaTim(int ans){ queue<int>q; int s,k; bool inq[N]={0}; for(int i=1;i<=n;i++) minTim[i]=-1; minTim[1]=T; q.push(1); while(!q.empty()) { s=q.front(); q.pop(); inq[s]=0; k=mapt[s].size(); for(int i=0;i<k;i++) if(mapt[s][i].c>=ans) { int v=mapt[s][i].v; if(minTim[v]<minTim[s]-mapt[s][i].t) { if(v==n) return true; minTim[v]=minTim[s]-mapt[s][i].t; if(!inq[v]) inq[v]=true,q.push(v); } } } return false;}int main(){ int cas,m,ans; EDG ss; scanf("%d",&cas); while(cas--) { scanf("%d%d%d",&n,&m,&T); for(int i=1;i<=n;i++) mapt[i].clear(); for(int i=1;i<=m;i++) { scanf("%d%d%d%d",&edg[i].u,&edg[i].v,&edg[i].c,&edg[i].t); ss.c=edg[i].c; ss.t=edg[i].t; ss.v=edg[i].v; mapt[edg[i].u].push_back(ss); ss.v=edg[i].u; mapt[edg[i].v].push_back(ss); } sort(edg+1,edg+1+m); int l=1,r=m,mid; ans=0; while(l<=r) { mid=(l+r)/2; if(spfaTim(edg[mid].c)) { ans=edg[mid].c; l=mid+1; } else r=mid-1; } printf("%d\n",ans); }}
0 0
- HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典
- hdu1839Delay Constrained Maximum Capacity Path(二分 + spfa)
- hdu1839Delay Constrained Maximum Capacity Path 二分+最短路
- 复习图---Delay Constrained Maximum Capacity Path(SPFA+二分)
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- hdu 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- hdu1839—Delay Constrained Maximum Capacity Path(spfa+二分)
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
- HDU1839---Delay Constrained Maximum Capacity Path(SPFA+vector+二分)
- hdu 1839 Delay Constrained Maximum Capacity Path【二分+SPFA】
- hdu 1839 Delay Constrained Maximum Capacity Path 二分下限+最短路spfa
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)
- HDU-1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU1839_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(最短路+二分)
- 二叉树
- wireshark抓包详细图文教程-02
- YTUOJ-手机尾号评分
- ZooKeeper监控
- 目标程序集不包含服务类型。可能需要调整此程序集的代码访问安全策略
- HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典
- 3.22
- 多少分
- FFMPEG命令
- Printf函数进栈顺序
- C++Builder 下的多线程介绍
- Linux使用技巧9--用dpkg管理你的软件
- 第五周程序阅读
- Linked List Cycle--LeetCode