Delay Constrained maximum capacity path
Time limit:10000 ms
Memory limit:65535kb
64bit Io format:% I64d & % i64usubmit status
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 shoshould have the highest capacity possible, in order to be able to transport simultaneously as your 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) shocould 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 balancer: n (2 <= n <= 10.000), m (1 <= m <= 50.000) and T (1 <= T <= 500.000 ). each of the next M lines will contain in 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
Given N points M and the maximum time t, each path has the maximum capacity and pass time, find the maximum limit of a path from 1 to n within the t time
The excess traffic from 1 to n depends on the capacity of the smallest route on the road. In this way, the traffic flow is divided into two parts based on the final traffic flow, and the possible traffic flow is enumerated to calculate the shortest time, if the time is less than or equal to the maximum time t, it will be increased until the minimum time is greater than T, so that the last pass is the maximum amount. Use spfa to simplify computational workload
Principle: as the number of connections increases, the number of edges that can be used is reduced, and the obtained shortest time remains unchanged or increases. In this way, the linear relationship between connections over shortest time is obtained. Eventually, as long as the shortest time does not exceed t, it can increase the throughput.
#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;struct node{ int x , y , v , w ; node *next ;} *head[20000];void add(int x,int y,int v,int w){ node *q = new node ; q->x = x ; q->y = y ; q->v = v ; q->w = w ; q->next = head[x] ; head[x] = q ;}int dis[20000] , vis[20000] ;queue <int> Q ;int spfa(int n,int mid){ memset(dis,INF,sizeof(dis)); memset(vis,0,sizeof(vis)); while( !Q.empty() ) Q.pop() ; dis[1] = 0 ; vis[1] = 1 ; Q.push(1); while( !Q.empty() ) { int x = Q.front() , y , v ; Q.pop() ; vis[x] = 0 ; for( node *q = head[x] ; q != NULL ; q = q->next ) { x = q->x ; y = q->y ; v = q->v ; if( v >= mid && dis[y] > dis[x] + q->w ) { dis[y] = dis[x] + q->w ; if( !vis[y] ) { vis[y] = 1; Q.push(y) ; } } } } return dis[n] ;}int main(){ int t , i , j , n , m , time ; node *q ; scanf("%d", &t); while(t--) { memset(head,NULL,sizeof(head)); scanf("%d %d %d", &n, &m, &time); int x , y , v , w , low = INF , top = 0 ; for(i = 0 ; i < m ; i++) { scanf("%d %d %d %d", &x, &y, &v, &w); add(x,y,v,w); add(y,x,v,w); low = min(low,v); top = max(top,v); } int mid , ans ; while(low <= top) { mid = (low + top)/2; if( spfa(n,mid) <= time ) { ans = mid ; low = mid + 1; } else top = mid - 1 ; } printf("%d\n", ans); } return 0;}