hdu1839之二分+邻接表+Dijkstra+队列优化
来源:互联网 发布:怎样投诉淘宝网 编辑:程序博客网 时间:2024/06/05 06:08
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
22 1 101 2 13 104 4 201 2 1000 152 4 999 61 3 100 153 4 99 4
Sample Output
1399
现在有东西要从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 99999999using 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+队列优化
- Dijkstra + 优先队列 + 邻接表优化
- Sicily 1031 Campus(Dijkstra[邻接表+优先队列优化])
- Sicily 1031 Campus(Dijkstra[邻接表+优先队列优化])
- Dijkstra[两种邻接表+优先队列优化]
- Dijkstra(邻接表+优先队列)
- Dijkstra 二分堆+邻接链表
- CUGB图论专场:B - ROADS(邻接表+dijkstra优先队列优化)
- UVA - 10986 Sending email (Dijkstra邻接表+优先队列优化)
- poj 1847 最短路 dijkstra模板(vector邻接表+队列优化)
- [POJ](3255)Roadblocks---- 最(次)短路径(邻接表+dijkstra优先队列优化)
- Dijkstra算法--邻接表存储+堆优化
- 最大二分图匹配 邻接表优化
- hdu1839 二分+最短路
- hdu1839 二分最短路
- HDU1839(最短路+二分)
- hdu1839 spfa+二分查找
- Dijkstra算法实现类—提高,邻接表+优先队列
- windows下svn+apache搭建svn服务器
- JavaScript实现继承---extend函数
- imageview的简单使用和bitmap的使用
- 突发奇想
- JavaScript继承详解(五)
- hdu1839之二分+邻接表+Dijkstra+队列优化
- Android项目为一个apk设置多个ICON图标和执行入口
- Windows下搭建PHP开发环境
- JS 实现地区,省份,城市,县区4级联动
- HDU 4677 Query on Graph
- mac安装pip
- [Android]几种常用控件使用
- uva 10985 Rings'n'Ropes 解题报告
- 《精通javascript》-----------------------读书笔记