最大流Dinic算法(当前弧优化)模板+例题

本文通过P3376和POJ-3281两道题目,介绍如何利用Dinic算法解决网络最大流问题。题目背景涉及母牛分配食物和饮料,通过拆点将问题转化为标准最大流问题,代码实现AC。
摘要由CSDN通过智能技术生成

P3376 网络最大流

 

 裸题模板:

/*---------------------------------
 *File name: Dinic.cpp
 *Creation date: 2020-05-19 10:32
 *-------------------------------*/
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define LL long long
#define PII pair<int, int>
#define Pque priority_queue 
#define loop(c, a, b) for(int c = a; c <= b; ++c)
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;

struct Edge{
	int to;
	int next;
	int w;
}edge[maxn * 2];
int head[maxn];
int cur[maxn];//当前弧优化数组
int n, m, s, t;
int dis[maxn];//Bfs深度
int cnt = 0;//边数

inline void init(){
	cnt = 0;
	memset(head, 0, sizeof head);
}

inline void Add_Edge(int u, int v, int w){
	edge[cnt].next = head[u]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值