Luogu P3376 最大流是网络流模型的一个基础问题. 网络流模型就是一种特殊的有向图. 概念: 源点:提供流的节点(入度为0),类比成为一个无限放水的水厂 汇点:接受流的节点(出度为0),类比成为一个无限收水的小区 弧:类比为水管 弧的容量:类比为水管的容量:用函数\(c(x,y)\)表示弧\((x,y)\)的容量 弧的流量:类比为当前在水管中水的量:用函数\(f(x,y)\)表示弧\((x,y)\)的流量 弧的残量:即容量-流量 容量网络:对于一个网络流模型,每一条弧都给出了容量,则构成…
https://www.luogu.org/blog/ONE-PIECE/wang-lao-liu-jiang-xie-zhi-dinic EK 292ms #include <bits/stdc++.h> using namespace std; int n, m, s, t, cnt; int l, r; struct node { int to, nex, val; }E[200005]; int head[100005]; int vis[10005]; int que[10005];…
题目:给出一个网络图,以及其源点和汇点,求出其网络最大流. 解法:网络流Dinic算法. 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<iostream> 5 #include<queue> 6 using namespace std; 7 8 const int N=10010,M=100010,INF=(int)1e9; 9 int n,m,st,e…
图论算法-网络最大流模板[EK;Dinic] EK模板 每次找出增广后残量网络中的最小残量增加流量 const int inf=1e9; int n,m,s,t; struct node{int v,cap;}; vector<node> map[100010]; int flow[10010][10010]; int a[100010]; int pre[100010]; int EK() { int maxf;//记录最大流量 queue<int> q; while(1) {…
前言 EK算法是求网络最大流的最基础的算法,也是比较好理解的一种算法,利用它可以解决绝大多数最大流问题. 但是受到时间复杂度的限制,这种算法常常有TLE的风险 思想 还记得我们在介绍最大流的时候提到的求解思路么? 对一张网络流图,每次找出它的最小的残量(能增广的量),对其进行增广. 没错,EK算法就是利用这种思想来解决问题的 实现 EK算法在实现时,需要对整张图遍历一边. 那我们如何进行遍历呢?BFS还是DFS? 因为DFS的搜索顺序的原因,所以某些毒瘤出题人会构造数据卡你,具体怎么卡应该比较简…
题目链接 https://www.luogu.com.cn/problem/P3376 题目大意 输入格式 第一行包含四个正整数 \(n,m,s,t\),分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来\(m\)行,每行包含三个正整数 \(u_i,v_i,w_i\),表示第 \(i\) 条有向边从 \(u_i\) 出发,到达 \(v_i\),边权为 \(w_i\)(即该边最大流量为 \(w_i\) ). 输出格式 一行,包含一个正整数,即为该网络的最大流. 题目解析 (待补充,咕咕咕…
话不多说上代码. Ford-Fulkerson(FF) #include <algorithm> #include <climits> #include <cstdio> #include <cstring> using namespace std; const int MAXN=100010,MAXM=200010; bool vis[MAXN]; int n,m,S,T,cnt,ans,head[MAXN]; struct edge { int nxt,…
我的作业部落有学习资料 可学的知识点 Dinic 模板 #define rg register #define _ 10001 #define INF 2147483647 #define min(x,y) (x)<(y)?(x):(y) using namespace std; ,cur[_],team[],depth[_]; struct pp { int next,to,w; }edge[(_<<)+(_<<)]; inline int read() { rg ,w=;…
今天学了网络最大流,EK 和 Dinic 主要就是运用搜索求增广路,Dinic 相当于 EK 的优化,先用bfs求每个点的层数,再用dfs寻找并更新那条路径上的值. EK 算法 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define maxn 1000001 #define INF 2147483647 us…
题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行包含三个正整数ui.vi.wi,表示第i条有向边从ui出发,到达vi,边权为wi(即该边最大流量为wi) 输出格式: 一行,包含一个正整数,即为该网络的最大流. 输入输出样例 输入样例#1: 4 5 4 3 4 2 30 4 3 20 2 3 20 2 1 30 1 3 40 输出样例#1: 50…