hdu 1839 Delay Constrained Maximum Capacity Path

最短路+二分。

对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加。

因为直接暴力一个一个容量去算会TLE,所以采用二分。

#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;

const int maxn = 10001;
const int INF = 0x7FFFFFFF;
struct aaa { int u, v, cc, tt; }node[500005];
vector<aaa>ljb[maxn];
int c[500005], dist[maxn], flag[maxn];
int n, m, t;

void spfa(int xianzhi)
{
    int iii;
    queue<int>Q;
    memset(flag, 0, sizeof(flag));
    for (iii = 0; iii<=n; iii++) dist[iii] = INF;
    dist[1] = 0; Q.push(1); flag[1] = 1;
    while (!Q.empty())
    {
        int h = Q.front(); Q.pop(); flag[h] = 0;
        for (iii = 0; iii<ljb[h].size(); iii++)
        {
            aaa u = ljb[h][iii];
            if (u.cc >= xianzhi)
            {
                if (u.u == h)
                {
                    if (dist[u.u] + u.tt <= dist[u.v])
                    {
                        dist[u.v] = dist[u.u] + u.tt;
                        if (flag[u.v] == 0)
                        {
                            Q.push(u.v);
                            flag[u.v] = 1;
                        }
                    }
                }
                else if (u.v == h)
                {
                    if (dist[u.v] + u.tt <= dist[u.u])
                    {
                        dist[u.u] = dist[u.v] + u.tt;
                        if (flag[u.u] == 0)
                        {
                            Q.push(u.u);
                            flag[u.u] = 1;
                        }
                    }
                }
            }
        }
    }
}

int main()
{
    int X;
    scanf("%d", &X);
    while (X--)
    {
        int i, j, u, v, tt;
        scanf("%d%d%d", &n, &m, &t);
        for (i = 0; i <= n; i++) ljb[i].clear();
        for (i = 0; i <= m; i++) node[i].tt = INF;
        for (i = 0; i < m; i++)
        {
            scanf("%d%d%d%d", &u, &v, &c[i], &tt);
            node[i].u = u; node[i].v = v;
            node[i].cc = c[i]; node[i].tt = tt;
            ljb[v].push_back(node[i]); ljb[u].push_back(node[i]);
        }
        sort(c, c + m);
        int anss = -1, xx, dd, zz;
        xx = 0; dd = m - 1; zz = (xx + dd) / 2;
        while (1)
        {
            spfa(c[zz]);
            if (dist[n] <= t) { anss = zz; xx = zz + 1; zz = (xx + dd) / 2; }
            else { dd = zz; zz = (xx + dd) / 2; }
            if (xx >= dd) break;
        }
        printf("%d\n", c[anss]);
    }
    return 0;
}
时间: 2024-11-05 23:14:35

hdu 1839 Delay Constrained Maximum Capacity Path的相关文章

HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)

题目地址:HDU 1839 我去..原来这题这么简单...网络流中这种二分建图的方式做了一大堆了..这种题还能难倒我吗...白天一直没怎么看懂题,对题意懵懵懂懂的...晚上好好看了看题,这不就是网络流中练的最多的那种二分建图模型吗....只是把网络流算法改成最短路就行了..但是两个地方手残了没能在实验室当场A掉..sad... 这题就是二分最小容量,对满足容量的加边,对时间求最短路.如果最短时间比规定时间少的话就可以继续增加容量,直到不能增加为止. 代码如下: #include <iostrea

hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)

Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1790    Accepted Submission(s): 577 Problem Description Consider an undirected graph with N vertices, nu

【HDU 1839】 Delay Constrained Maximum Capacity Path(二分+最短路)

[HDU 1839] Delay Constrained Maximum Capacity Path(二分+最短路) Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1515    Accepted Submission(s): 481 Problem

复习图---Delay Constrained Maximum Capacity Path(SPFA+二分)

Delay Constrained Maximum Capacity Path Time Limit:10000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Description Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with

HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典

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, n

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

解题报告 http://blog.csdn.net/juncoder/article/details/38349019 题目传送门 题意: 有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点.走每条边的运输容量为C,运送时间为D. 他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大. 一条路径的运输容量取决与这条路径中的运输容量最小的那条边. 思路: 二分容量建图,spfa判时间是否符合条件 #incl

hdu1839Delay Constrained Maximum Capacity Path 二分+最短路

//一个无向图,两点之间的流量为c,两点花的时间为t //问从起点到终点n之间时间小于等于T且只走一条路径能够运输的最大流量为多少 //二分流量,小于这个流量的路径不走,求其时间是否小于等于T得到答案 #include<cstdio> #include<cstring> #include<iostream> #include<queue> using namespace std ; const int maxn = 10010 ; const int max

HDU 4002 Find the maximum(数论-欧拉函数)

Find the maximum Problem Description Euler's Totient function, φ (n) [sometimes called the phi function], is used to determine the number of numbers less than n which are relatively prime to n . For example, as 1, 2, 4, 5, 7, and 8, are all less than

hdu 5052 Yaoge’s maximum profit

Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 442    Accepted Submission(s): 122 Problem Description Yaoge likes to eat chicken chops late at night. Yaoge has eaten too