
网络流
吴俊达9812
这个作者很懒,什么都没留下…
展开
-
ACWing 380 舞动的夜晚( 二分图的可行边与必经边 )
二分图最大匹配的可行边与必经边。#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 50005;const lint maxm = 5000000 + 5;int n,m,tot;int he[maxn],ne[maxm...原创 2019-11-07 16:21:15 · 650 阅读 · 0 评论 -
牛客多校第五场 F (最大点独立集)
二分图最大点独立集 (补集为最小点覆盖)网络流做法,执行完最大流后,与S连通的左部点和不与S连通的右部点为最大点独立集。#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint maxn = 5000 + 100;const lint ma...原创 2019-11-07 15:15:57 · 144 阅读 · 0 评论 -
2018 icpc nanjing magic potion
#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const int inf=0x3f3f3f3f;struct dinic{ static const int N = 1000005; static const int M = 20000005...原创 2019-11-05 22:18:38 · 113 阅读 · 0 评论 -
UOJ #2893. 征服王
题意:起点和终点有限制的最小可重复路径覆盖。思路1:上下界网络流,拆点,使得每个点的流量下界限制为1.(注意有源汇上下界网络流只能跑DAG)#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint inf = 0x3f3f3f3f;cons...原创 2019-11-02 22:53:14 · 241 阅读 · 0 评论 -
UOJ 2718 毕业旅行(diworth定理)
题意:思路:Dilworth定理:对于一个偏序集,最少链划分等于最长反链长度。 Dilworth定理的对偶定理:对于一个偏序集,其最少反链划分数等于其最长链的长度。 最长反链=最小路径覆盖 floyd传递闭包后,用n-二分图最大匹配数即为答案(因为是点可重最小路径覆盖,所以要先用floyd求传递闭包)#include ...原创 2019-11-02 14:38:27 · 273 阅读 · 0 评论 -
bzoj 2400(最小割)
题意:定义无向图中的一条边的值为:这条边连接的两个点的值的异或值。定义一个无向图的值为:这个无向图所有边的值的和。给你一个有n个结点m条边的无向图。其中的一些点的值是给定的,而其余的点的值由你决定(但要求均为非负数),使得这个无向图的值最小。在无向图的值最小的前提下,使得无向图中所有点的值的和最小。思路:最小割按位做枚举每一位一个点与S联通表示这个点选0,与T联通表示这个...原创 2019-11-02 14:04:05 · 185 阅读 · 0 评论 -
UOJ 1497 最大获利(最大密度子图变形)
胡泊涛论文题注意要连双向边。#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;//const double eps = 1e-8;const int maxn = 5005;const int maxm = 500005;namespace MF{...原创 2019-10-30 19:42:50 · 187 阅读 · 0 评论 -
UOJ #4213. 贪吃蛇(上下界可行费用流)
思路:限制每个点的度数为2 ,边界点的度数可以花费1的代价减少1个度数坑点:我TM以后再也不用 ++ r 的优先级了,这个玩意在 C++ 和 C++11中不一样,而且TM错都不知道咋错的,我TM调了一个晚上就TM这么没了。。。。#include <bits/stdc++.h>using namespace std;typedef int lint;typedef lo...原创 2019-10-29 23:08:50 · 201 阅读 · 0 评论 -
bzoj 3876 支线剧情(上下界最小费用可行流)
题意:给定个一个DAG,每条边至少被覆盖一次,且有一个代价,问从起点开始的路径覆盖所有边至少一次的最小代价。思路:上下界最小费用可行流。#include <bits/stdc++.h>using namespace std;typedef int lint;typedef long long LL;const int inf = 0x3f3f3f3f;const i...原创 2019-10-29 19:14:47 · 229 阅读 · 0 评论 -
网路流24题---负载平衡问题
#include <bits/stdc++.h>using namespace std;typedef int lint;typedef long long LL;const int maxn = 105;const int inf = 0x3f3f3f3f;struct EDGE { int from, to, next, cost, cap; // 如果需...原创 2019-10-17 13:53:18 · 127 阅读 · 0 评论 -
网络流24题----数字三角形
模拟费用流注意,费用流不可以跑残余网络。#include <bits/stdc++.h>using namespace std;typedef int lint;typedef long long LL;const int maxn = 50;const int maxm = 50;const int inf = 0x3f3f3f3f;struct EDGE {...原创 2019-10-17 12:24:53 · 116 阅读 · 0 评论 -
网络流24题--方格取数
思路:最小割#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint inf = 0x3f3f3f3f;struct dinic{ static const int N = 50005; static const int M =...原创 2019-10-16 21:34:58 · 109 阅读 · 0 评论 -
网络流24题--最长不下降子序列个数
残余网络#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint inf = 0x3f3f3f3f;const int maxn = 1005;struct dinic{ static const int N = 5005; ...原创 2019-10-16 21:02:56 · 115 阅读 · 0 评论 -
网络流24题 --最小路径覆盖(要求输出方案)
注意网路流的边为二倍。#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint inf = 0x3f3f3f3f;const int maxn = 1005;vector<int> ve[maxn];struct dinic{...原创 2019-10-16 19:45:25 · 229 阅读 · 0 评论 -
网络流24题---圆桌问题
#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint inf = 0x3f3f3f3f;const int maxn = 275;const int maxm = 155;struct dinic{ static const int...原创 2019-10-16 20:32:11 · 188 阅读 · 0 评论 -
网络流24题---魔术球
思路:注意 在残余网络上跑出的流量需要和之前的结果进行累加。#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef int lint;const lint inf = 0x3f3f3f3f;const int maxn = 20005;vector<int> ve[m...原创 2019-10-16 20:13:37 · 96 阅读 · 0 评论 -
UOJ #3265. 志愿者招募加强版
题意:思路:线性规划的题都可以用网络流来解决。 具体思路是 差分之后每一对正的和负的之间连边。inf的边起调节作用。#include <bits/stdc++.h>using namespace std;typedef int lint;typedef long long LL;const int inf = 0x3f3f3f3f;const i...原创 2019-10-16 16:05:35 · 170 阅读 · 0 评论 -
ctsc 1999 家园(24题)
这题明显要根据时间进行拆点,问题是不知道要拆多少个。最开始我想用二分,但最坏情况下跑网络流会超时,所以无法判断上界。尔对于这种情况,我们可以动态加点,然后在上一次的残余网络上继续跑最大流。这样的好处就是不用判断上届而且每次跑网络流的时候增广的比较少,时间复杂度得到保证。(猜想时间复杂度应该就和直接在最终的图上跑网络流的复杂度差不多)。#include <bits/stdc++.h&g...原创 2019-06-26 16:09:36 · 199 阅读 · 0 评论 -
bzoj 1565植物大战僵尸
题意:很麻烦,就不说了思路:有向闭合图:闭合图中任意点的后继还在闭合图中。 物理意义:一个事件发生,他所有的前提都需要发生 在任意有向带权图中,只要有依赖关系需要解决,最大权闭合子图都普遍成立。 拓扑排序中没有遍历到的点就是不可达点,不可达点不能在网络流中出现。为啥呢,我试了一下,把这些点放入网络流中 ...原创 2019-05-16 22:22:47 · 146 阅读 · 0 评论 -
bzoj2661
常用技巧,答案除以2#include <bits/stdc++.h>using namespace std;typedef int LL;const LL maxn = 10000;const LL maxm = 4000000;const LL inf = 0x3f3f3f3f;struct mcmf{ LL he[maxn],tot,edge[maxm]...原创 2019-05-16 16:00:44 · 154 阅读 · 0 评论 -
bzoj2424
水题#include <bits/stdc++.h>using namespace std;typedef long long LL;const LL maxn = 10000;const LL maxm = 1000000;const LL inf = 0x3f3f3f3f3f3f3f3f;struct mcmf{ LL he[maxn],tot,edge...原创 2019-05-16 15:59:06 · 103 阅读 · 0 评论 -
bzoj 1927
题意:一个无向图,每条边告诉你通过时间,还可以直接在任意两点之间进行跳跃,跳跃时间只与终点有关,且时间已知。问最小时间哈密顿通路。思路:用二分图匹配比较好想。考虑最小路径覆盖,有流流过一条边代表选择这条边。右部点是入度点,失配的入度点代表最小路径覆盖中边的起始点。而这些起始点可以通过跳跃到达,所以只需在最小路径覆盖的基础上加上跳跃到达的方式,即从S向每个入度点连接费用为a[ i ]边。一定需要...原创 2019-05-15 10:29:46 · 107 阅读 · 0 评论 -
bzoj1061 志愿者招募
题意:给m类志愿者,第i个志愿者从第 l[ i ] 天工作到第 r[ i ] 天,费用为c[ i ]。每种志愿者可以选择无限多人。 每一天都有给定的最少志愿者数目要求a[ i ],求费用最小的选择方案,输出费用。思路:明显是一道线性规划可以解决的问题,但我不会写单纯型。听溪哥说线性规划都有网络流的等价形式,不过我在网上没有找到,知道的dalao可以给我留个言吗。进...原创 2019-05-14 21:58:11 · 201 阅读 · 1 评论 -
bzoj 3280 小R的烦恼
题意:n天,m个学校,k个医院。每天需要a[i]个人,这a[i]个人工作后处于濒死状态,你可以选择把濒死状态的人送去医院,治好后还可以继续工作。每个医院i救治一个人需要d[i]天,费用q[i]元。学校 i 中一个人工作一天薪酬为p[ i ].思路: 时间为一个天然序,第i天的决策为从健康的人中选择a[i]个人。并且这a[i]个人变为濒死的人。流量可以理解为决策的选择。那么...原创 2019-05-14 11:06:50 · 181 阅读 · 0 评论 -
太空飞行计划问题( 24题 )
最大闭合权子图复习最后的 s 所在的连通分量为 闭合子图#include <bits/stdc++.h>using namespace std;typedef int LL;typedef int lint;const LL maxn = 1000;const LL maxm = 1000000;const LL inf = 0x3f3f3f3f;struct...原创 2019-06-26 17:21:41 · 305 阅读 · 0 评论 -
poj 1637 Sightseeing tour 混合图欧拉回路模板(不考虑不连通的情况)
#include <cstdio>#include <algorithm>#include <queue>#include <cstring>using namespace std;typedef int lint;const int maxn = 10005;const int maxm = 20005;const lint in...原创 2019-09-17 12:37:46 · 135 阅读 · 0 评论 -
ISAP 模板
#include<bits/stdc++.h>using namespace std;typedef long long lint;typedef long long LL;const lint maxn = 10010;const lint maxm = 10010;const LL INF = 0x3f3f3f3f3f3f3f3f;lint tot,ver[maxm...原创 2019-09-18 16:41:47 · 212 阅读 · 0 评论 -
codeforces 510E
题意:n个人,把他们围成几个圆圈,每个圆圈至少有3个人,并且相邻的两个人的标号只和为质数。思路:首先按照奇偶拆分成二分图,然后原点向每个左部点连流量为2的边,每个右部点向汇点连流量为2的边。代表每个点左右有两个人。这题要求输出方案。从左部点到右部点 edge[ cure ] = 0 代表这条有向边被选中,如果从右部点到左部点,edge[ cure ^1 ] = 0,代表这条边的反向边被选中...原创 2019-10-05 16:43:01 · 161 阅读 · 0 评论 -
codeforces 635 D
题目大意:有n个城市,有m条有向边,对应有x个熊搬东西。接下来m条有向边的输入三个元素,表示起点终点以及这条路径上总共最多可以运送多少货物。问需要每只熊都搬动相同重量的东西从点1到点n,问最多能够送过去多少重量的货物。思路:可以形象地理解为x条路径,每条路径的流量相同。问最大流量是多少。二分这个流量,把边权的流量值转化为可以通过熊的个数。#include <bits/s...原创 2019-10-05 17:44:46 · 161 阅读 · 0 评论 -
codeforces 546E
题目大意:有n个城市,有m条无向边,接下来第一行,n个数,表示每个城市现在有的士兵的数量,再接下来一行,n个数,表示每个城市需要有的士兵的数量,不能多也不能少,而且每个城市的士兵要么原地不动,要么只能移动到其直接相连的城市去(个数不限),问是否有可行方案,如果有可行方案输出出来。思路:拆点建图。#include <bits/stdc++.h>using namespac...原创 2019-10-05 19:31:15 · 128 阅读 · 0 评论 -
最长k可重区间集合(24题)
这题最开始再网络赛的时候遇到,第一想法是贪心或者dp,然后发现需要记录的转态太多了。一看区间个数又很想网络流,所以就yy出了一个假算法,太丑了就不说了。这题正确的思路是将答案拆分成k条路径,每条路径满足包含的区间之间互相没有交集。如果将这k条路径按照包含区间的个数排序,那么满足的关系就是下一个路径包含的区间一定被上一个路径的区间所包含。问题转化为k条路径的最大费用。#include...原创 2019-06-26 10:53:38 · 238 阅读 · 0 评论