#include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long long LL; ; const int INF = 0x3f3f3f3f; struct edge{ int u, v, cap, flow, cost, nex; } edges[maxm]; int head[maxm], cur[maxm], cnt, fa[maxm], d[maxm], n; bool…
EK  + dijkstra (2246ms) 开氧气(586ms) dijkstra的势 可以处理负权 https://www.luogu.org/blog/28007/solution-p3381 #include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n, m, s, t, cnt; struct node { int to, nex, val, cost; }E[100005]; int head[5…
题目:给出一个网络图,以及其源点和汇点,每条边已知其最大流量和单位流量费用,求出其网络最大流和在最大流情况下的最小费用. 解法:在Dinic的基础下做spfa算法. 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<iostream> 5 #include<queue> 6 using namespace std; 7 8 const int N=5010,…
记得把数组开大一点,不然就RE了... 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 const int N=5e5; 5 const int M=5e5; 6 const int INF=0x3f3f3f3f; 7 8 int n,m,s,t,ans,d[N],maxflow; 9 int tot=1,adj[N],nex[M],to[M],cap[M],cost[M]; 10 bool…
题目链接 Update:我好像刚知道多路增广就是zkw费用流.. //1314ms 2.66MB 本题优化明显 #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> //#define gc() getchar() #define MAXIN 350000 #define gc() (SS==TT&&…
#include <iostream> #include <cstring> #include <cstdio> #include <queue> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; , INF = 0x7fffffff; int head[maxn], d[maxn], vis[maxn], p[maxn], f[maxn]; int n, m, s, t; int flo…
[SDOI2009]晨跑 最小费用最大流的板子题吧 令 \(i'=i+n\) \(i -> i'\) 建一条流量为1费用为0的边这样就不会对答案有贡献 其次是对 \(m\) 条边建 \(u'->v\) 流量为1费用为cost反向为0费用为-cost (单向边,不管 这样建图就有从必须令 \(1'\)为源点 \(n\) 为汇点 然后每条流的路线都是 \(1' -> u_1 -> u_1' -> u_2 -> u_2' -> ... -> n\) 于是就可以直接…
题面:[模板]最小费用最大流 代码: #include<cstdio> #include<cstring> #include<iostream> #include<queue> #define ll long long #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) using namespace std; inline ll rd(){ ll x=,f=…
题目链接 哈  学会最小费用最大流啦 思路是这样. 首先我们有一个贪心策略.如果我们每次找到单位费用和最短的一条增广路,那么显然我们可以把这条路添加到已有的流量里去——不管这条路的流量是多大,反正它能扩大现有流量,而且目前为止它是可以扩大流量的所有路径中单位花费最少的. 然后我们就把这条路填上.想想看当我们找不到这样一条路的时候会发生什么? 那就是没有增广路了.恭喜我们获得最小费用最大流.这是为什么呢? 首先没有任何一条增广路的时候我们肯定获得最大流没错 然后我们回顾我们扩展的方式.每次我们都选…
P3381 [模板]最小费用最大流 题目描述 如题,给出一个网络图,以及其源点和汇点,每条边已知其最大流量和单位流量费用,求出其网络最大流和在最大流情况下的最小费用. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行包含四个正整数ui.vi.wi.fi,表示第i条有向边从ui出发,到达vi,边权为wi(即该边最大流量为wi),单位流量的费用为fi. 输出格式: 一行,包含两个整数,依次为最大流量和在最大流量情况下的…