Loading [MathJax]/jax/input/TeX/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Drainage Ditches (HDU - 1532)(最大流)

Drainage Ditches (HDU - 1532)(最大流)

作者头像
Lokinli
发布于 2023-03-09 09:00:25
发布于 2023-03-09 09:00:25
15900
代码可运行
举报
文章被收录于专栏:以终为始以终为始
运行总次数:0
代码可运行

HDU - 1532

题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少?

题解:最大流模板题。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 0x3ffffff;
const int maxn = 205;
int gra[maxn][maxn];
int flow[maxn];
int path[maxn];
int n,m;

int bfs(int s, int e)
{
    queue<int>q;
    int t;
    memset(path,-1,sizeof(path));
    memset(flow,0,sizeof(flow));
    path[s] = 0;
    flow[s] = INF;
    q.push(s);
    while(!q.empty()){
        t = q.front();
        q.pop();
        if(t == e) break;
        for(int i = 1; i <= m; i ++)
        {
            if(i != s && gra[t][i] && path[i] == -1)
            {
                flow[i] = flow[t] < gra[t][i] ? flow[t] : gra[t][i];
                path[i] = t;
                q.push(i);
            }
        }
    }
    if(path[e] == -1)
        return -1;
    else return flow[e];
}

int EK(int s, int e){
    int maxflow = 0;
    int pre, now, step;
    while((step = bfs(s,e))!= -1){
        maxflow += step;
        now = e;
        while(now != s){
            pre = path[now];
            gra[pre][now] -= step;
            gra[now][pre] += step;
            now = pre;
        }
    }
    return maxflow;
}
int main()
{

    int u,v,c;
    while(~scanf("%d%d",&n,&m)){
        memset(gra,0,sizeof(gra));
        for(int i = 1; i <= n; i ++)
        {
            scanf("%d %d %d", &u,&v,&c);
            gra[u][v] += c;
        }
        int ans = EK(1,m);
        printf("%d\n",ans);
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-10-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
图论--网络流最大流问题
问题表述:给定一幅图(n个结点,m条边),每一条边有一个容量,现在需要将一些物品从结点s(称为源点)运送到结点t(称为汇点),可以从其他结点中转,求最大的运送量。
风骨散人Chiam
2020/10/28
1.5K0
图论--网络流最大流问题
网络流--最大流--EK模板
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #define INF 0x3f3f3f3f using namespace std; int n,m; const int maxn=1005; int g[maxn][maxn];//容量
风骨散人Chiam
2020/10/28
6400
Tricks Device (hdu 5294 最短路+最大流)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 124 Accepted Submission(s): 27
全栈程序员站长
2022/07/10
2350
网络流--最大流--HDU 3549 Flow Problem
Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.
风骨散人Chiam
2020/10/28
3210
最大流
最大流算法主要分为两大类,一类为增广路算法,一类为预流推进算法。最大流算法解决的是在有向网路图 中计算从源点 到汇点 的最大流量问题,以及最小割容量问题。
hotarugali
2022/03/01
9000
网络最大流算法—EK算法
前言 EK算法是求网络最大流的最基础的算法,也是比较好理解的一种算法,利用它可以解决绝大多数最大流问题。 但是受到时间复杂度的限制,这种算法常常有TLE的风险 思想 还记得我们在介绍最大流的时候提到的求解思路么? 对一张网络流图,每次找出它的最小的残量(能增广的量),对其进行增广。 没错,EK算法就是利用这种思想来解决问题的 实现 EK算法在实现时,需要对整张图遍历一边。 那我们如何进行遍历呢?BFS还是DFS? 因为DFS的搜索顺序的原因,所以某些毒瘤出题人会构造数据卡你,具体怎么卡应该比较简单,不
attack
2018/04/11
5.1K0
网络最大流算法—EK算法
网络流--最大流--POJ 1273 Drainage Ditches
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
风骨散人Chiam
2020/10/28
3320
EK (Edmond-Karp) 算法 学习笔记
EK (Edmond-Karp) 算法,说白了就是求最大流/费用流之类的问题的算法。
yzxoi
2022/09/19
7800
EK (Edmond-Karp) 算法 学习笔记
图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)
Our geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. Her factory has introduced M new machines in order to process the coming N tasks. For the i-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. However, a task can be interrupted and processed on different machines on different days. Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
风骨散人Chiam
2020/10/28
4250
图论--网络流--最大流 HDU 2883 kebab(离散化)
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled
风骨散人Chiam
2020/10/28
2970
网络流--最大流--POJ 1459 Power Network
A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= pmax(u) of power, may consume an amount 0 <= c(u) <= min(s(u),cmax(u)) of power, and may deliver an amount d(u)=s(u)+p(u)-c(u) of power. The following restrictions apply: c(u)=0 for any power station, p(u)=0 for any consumer, and p(u)=c(u)=0 for any dispatcher. There is at most one power transport line (u,v) from a node u to a node v in the net; it transports an amount 0 <= l(u,v) <= lmax(u,v) of power delivered by u to v. Let Con=Σuc(u) be the power consumed in the net. The problem is to compute the maximum value of Con.
风骨散人Chiam
2020/10/28
3520
网络流--最大流--POJ 1459 Power Network
hdu------(3549)Flow Problem(最大流(水体))
Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 8203    Accepted Submission(s): 3817 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, you
Gxjun
2018/03/26
6560
[2019HDU多校第一场][HDU 6582][E. Path]
题意: t 组样例,n个点,m条边。i 行a到b距离c. 要求去掉最短路的最小代价。去掉每条路代价等于长度。
用户2965768
2019/08/01
3080
HDU 3468 Treasure Hunting(BFS+网络流之最大流)
首先标记方法是,对每个集合点跑一次bfs,记录全部点到该点的最短距离。然后对于随意一对起始点来说,仅仅要这个点到起点的最短距离+该点到终点的最短距离==起点到终点的最短距离,就说明这点在某条从起点到终点的最短路上。
全栈程序员站长
2022/07/12
2870
网络流的最大流入门(从普通算法到dinic优化)
网络流(network-flows)是一种类比水流的解决问题方法,与线性规划密切相关。网络流的理论和应用在不断发展。而我们今天要讲的就是网络流里的一种常见问题——最大流问题。
233333
2020/02/11
3.1K0
网络流的最大流入门(从普通算法到dinic优化)
PAT「1003 Universal Travel Sites (35分)」
题目链接:PAT「1003 Universal Travel Sites (35分)」 。
hotarugali
2022/03/01
5050
图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)
Gabiluso is one of the greatest spies in his country. Now he’s trying to complete an “impossible” mission ----- to make it slow for the army of City Colugu to reach the airport. City Colugu has n bus stations and m roads. Each road connects two bus stations directly, and all roads are one way streets. In order to keep the air clean, the government bans all military vehicles. So the army must take buses to go to the airport. There may be more than one road between two bus stations. If a bus station is destroyed, all roads connecting that station will become no use. What’s Gabiluso needs to do is destroying some bus stations to make the army can’t get to the airport in k minutes. It takes exactly one minute for a bus to pass any road. All bus stations are numbered from 1 to n. The No.1 bus station is in the barrack and the No. n station is in the airport. The army always set out from the No. 1 station. No.1 station and No. n station can’t be destroyed because of the heavy guard. Of course there is no road from No.1 station to No. n station. Please help Gabiluso to calculate the minimum number of bus stations he must destroy to complete his mission.
风骨散人Chiam
2020/10/28
3790
图论--网络流--最大流--POJ 1698 Alice's Chance
Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn't want to miss any of them!! You are asked to tell her whether she can act in all the films. As for a film,
风骨散人Chiam
2020/10/28
4250
图论--网络流--最大流--POJ 3281 Dining (超级源汇+限流建图+拆点建图)
Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others.
风骨散人Chiam
2020/10/28
4580
图论--网络流--最大流--POJ 3281 Dining (超级源汇+限流建图+拆点建图)
洛谷P3254 圆桌问题(最大流)
题意 $m$个不同单位代表参加会议,第$i$个单位有$r_i$个人 $n$张餐桌,第$i$张可容纳$c_i$个代表就餐 同一个单位的代表需要在不同的餐桌就餐 问是否可行,要求输出方案 Sol 比较zz的最大流 从$S$向$1-m$连流量为$r_i$的边 从$m + 1$向$m + n$连流量为$c_i$的边 从$1-m$向$m + 1$到$m + n$中的每个点连流量为$1$的边 跑最大流即可 #include<cstdio> #include<queue> #include<cstring> using
attack
2018/07/27
2790
相关推荐
图论--网络流最大流问题
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验