码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1839_Delay Constrained Maximum Capacity Path(最短路+二分)

时间:2014-08-02 18:31:13      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   strong   

解题报告

http://blog.csdn.net/juncoder/article/details/38349019

题目传送门

题意:

有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。
他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。
一条路径的运输容量取决与这条路径中的运输容量最小的那条边。

思路:

二分容量建图,spfa判时间是否符合条件

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define inf 99999999
using namespace std;
int n,m,T;
struct node {
    int u,v,w,t,next;
} edge[501000],N[101000];
int head[101000],cnt;
void add(int u,int v,int w)
{
    edge[cnt].v=v;
    edge[cnt].t=w;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
int spfa()
{
    int i,j,dis[10100],vis[10100];
    for(i=1; i<=n; i++) {
        dis[i]=inf;
        vis[i]=0;
    }
    dis[1]=0;
    vis[1]=1;
    queue<int>Q;
    Q.push(1);
    while(!Q.empty()) {
        int u=Q.front();
        Q.pop();
        vis[u]=0;
        for(i=head[u]; i!=-1; i=edge[i].next) {
            if(dis[edge[i].v]>dis[u]+edge[i].t) {
                dis[edge[i].v]=dis[u]+edge[i].t;
                if(!vis[edge[i].v]) {
                    vis[edge[i].v]=1;
                    Q.push(edge[i].v);
                }
            }
        }
    }
    if(dis[n]<=T)
        return 1;
    return 0;
}
int slove(int mid)
{
    memset(edge,0,sizeof(edge));
    memset(head,-1,sizeof(head));
    cnt=0;
    for(int i=1; i<=m; i++) {
        if(N[i].w>=mid) {
            add(N[i].u,N[i].v,N[i].t);
            add(N[i].v,N[i].u,N[i].t);
        }
    }
    if(spfa())return 1;
    return 0;
}
int main()
{
    int tt,i,j;
    scanf("%d",&tt);
    while(tt--) {
        memset(N,0,sizeof(N));
        scanf("%d%d%d",&n,&m,&T);
        int l=0,r=-1;
        for(i=1; i<=m; i++) {
            scanf("%d%d%d%d",&N[i].u,&N[i].v,&N[i].w,&N[i].t);
            if(N[i].w>r)
                r=N[i].w;
        }
        int maxx=-1;
        while(l<=r) {
            int mid=(l+r)/2;
            if(slove(mid)) {
                l=mid+1;
                maxx=mid;
            } else r=mid-1;
        }
        printf("%d\n",maxx);
    }
    return 0;
}

Delay Constrained Maximum Capacity Path

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1035    Accepted Submission(s): 318


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
 


HDU1839_Delay Constrained Maximum Capacity Path(最短路+二分),布布扣,bubuko.com

HDU1839_Delay Constrained Maximum Capacity Path(最短路+二分)

标签:des   style   blog   http   color   java   os   strong   

原文地址:http://blog.csdn.net/juncoder/article/details/38349019

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!