Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 91585   Accepted: 35493 Description 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…
hdu 1532 题目大意: 就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速,本题就是让你求出最大流速,无疑要运用到求最大流了.题中N为水沟数,M为水沟的顶点,接下来Si,Ei,Ci分别是水沟的起点,终点以及其容量.求源点1到终点M的最大流速.注意重边 Dinic算法的实现有以下几个步骤: 1:初始化容量网络和网络流 2:构造残留网络和层次网络,若汇点不在层次网络中则算法结束 输出最大流 3:在层次网络中用一次DFS进行增…
题意:有一个N行M列的正整数矩阵,输入N个前1~N行所有元素之和,以及M个前1~M列所有元素之和.要求找一个满足这些条件,并且矩阵中的元素都是1~20之间的正整数的矩阵.输入保证有解,而且1≤N,M≤20. 解法:这题的图转换得极妙!(*^▽^*)   我们可以发现找到的矩阵需要满足3个条件:1.N行M列:2.各行各列的和:3.各元素的大小.再仔细阅读一次题目,发现题目中提到的2个数字相同--"20",再想想这是不是有什么玄机.     首先可以找到第3个条件的转化,可以用容量来限制,…
题意:有N个插头,M个设备和K种转换器.要求插的设备尽量多,问最少剩几个不匹配的设备. 解法:给读入的各种插头编个号,源点到设备.设备通过转换器到插头.插头到汇点各自建一条容量为1的边.跑一次最大流就可得到最多匹配的设备数. 注意啊,我这个代码在神奇的地方死循环了--判断队列为空的语句......Σ( ° △ °|||)︴所以大家主要看"行文思路" ? :-) 1 #include<cstdio> 2 #include<cstdlib> 3 #include&l…
Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their preferences. Although…
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stick). Have you, however, considered about the hardship of a kebab roaster while enjoying the delicious food? Well, here's a chance f…
Description 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 mak…
Description Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The contact list has become so long that it often takes a long time for her to browse through the whole list to f…
题目描述 给定 nn 个点,mm 条有向边,给定每条边的容量,求从点 ss 到点 tt 的最大流. 输入格式 第一行包含四个正整数nn.mm.ss.tt,用空格分隔,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来mm行每行包含三个正整数u_iui​.v_ivi​.c_ici​,用空格分隔,表示第ii条有向边从u_iui​出发,到达v_ivi​,容量为c_ici​ 输出格式 一个整数,表示ss到tt的最大流 输入输出样例 输入 #1  7 14 1 7 1 2 5 1 3 6 1 4…
Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step h…
Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area there are N shopkeepers (marked from 1 to N) which stocks goods from him.Dearboy has M supply places (marked from 1 to M), each provides K di…
Problem Description 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…
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; typedef long long ll; #define space putchar(' ') #define enter putchar('\n') #define INF 0x7fffffff template <class T> void read(…
Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71559   Accepted: 27846 Description 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…
题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; #define N 200010 #define INF 0x3fffffff inline int read()…
网络流最大流算法dinic ps:本文章不适合萌新,我写这个主要是为了复习一些细节,概念介绍比较模糊,建议多刷题去理解 例题:codevs草地排水,方格取数 [抒情一下] 虽然老师说这个多半不考,但是学了没坏处,所以我就把这算法学了(准确说是补起了QAQ) 以前一直觉得dinic的代码好长好难啊,然后就知难而退 最近学了很多和看了很多以后,咱们就学会了知男♂而上了,所以我果断的回来上dinic了 [dinic] Dinic算法是用来做最大流一类题的,代码有一丢丢的长,但其实说白了就是一个bfs+…
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the game of playing house we used to play when we are kids. What a happy time as…
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2909 Accepted Submission(s): 942 Problem Description Alice and Bob are playing together. Alice is crazy about art and she h…
题目描述 Alice和Bob做游戏,给出一张有向图表示运输网络,Alice先给Bob一种最大流方案,然后Bob在所有边上分配总和等于P的非负费用.Alice希望总费用尽量小,而Bob希望总费用尽量大.求两人都采取最优策略的情况下最大流及总费用. 输入 第一行三个整数N,M,P.N表示给定运输网络中节点的数量,M表示有向边的数量,P的含义见问题描述部分.为了简化问题,我们假设源点S是点1,汇点T是点N.接下来M行,每行三个整数A,B,C,表示有一条从点A到点B的有向边,其最大流量是C. 输出 第一…
题目描述 WJJ喜欢“魔兽争霸”这个游戏.在游戏中,巫妖是一种强大的英雄,它的技能Frozen Nova每次可以杀死一个小精灵.我们认为,巫妖和小精灵都可以看成是平面上的点. 当巫妖和小精灵之间的直线距离不超过R,且巫妖看到小精灵的视线没有被树木阻挡(也就是说,巫妖和小精灵的连线与任何树木都没有公共点)的话,巫妖就可以瞬间杀灭一个小精灵. 在森林里有N个巫妖,每个巫妖释放Frozen Nova之后,都需要等待一段时间,才能再次施放.不同的巫妖有不同的等待时间和施法范围,但相同的是,每次施放都可以…
题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possible. He has hidden in it deep within his farm and needs to be able to get to the machine without being detected. He must make a total of T (1 <= T <=…
题目描述 Dicing 是一个两人玩的游戏,这个游戏在Byteotia非常流行. 甚至人们专门成立了这个游戏的一个俱乐部. 俱乐部的人时常在一起玩这个游戏然后评选出玩得最好的人.现在有一个非常不走运的家伙,他想成为那个玩的最好的人,他现在知道了所有比赛的安排,他想知道,在最好的情况下,他最少只需要赢几场就可以赢得冠军,即他想知道比赛以后赢的最多的那个家伙最少会赢多少场. 输入 第一行两个整数n 和 m, 1 <= n <= 10 000, 0 <= m <= 10 000; n 表…
图论-zkw费用流 模板 这是一个求最小费用最大流的算法,因为发明者是神仙zkw,所以叫zkw费用流(就是zkw线段树那个zkw).有些时候比EK快,有些时候慢一些,没有比普通费用流算法更难,所以学zkw费用流之前,不需要先掌握普通费用流. 前置知识:\(\texttt{网络最大流}\). 在学了网络最大流后,如果在没条边上加个限制,就是 \(cost\),表示这条边上每走过 \(1\) 流量就要付费 \(cost\),求在最大流的情况下,要交的最少费用. 如上费用流图,最大流为 \(1\),在…
Power Network 时间限制: 1 Sec  内存限制: 128 MB 题目描述 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…
<题目链接> 题目大意: 一个农夫他家的农田每次下雨都会被淹,所以这个农夫就修建了排水系统,还聪明的给每个排水管道设置了最大流量:首先输入两个数n,m ;n为排水管道的数量,m为节点的数量,接下来就是n行数,每一行分为x1,x2,x3:x1,x2为节点的序号,x3为流量:然后问从1号节点到m号节点的最大流是多少? 解题分析: 网络流最大流裸题,下面用的是EK算法,bfs起搜索增广路径的作用,EK算法比较难理解的地方就是反向边的构造. #include <cstdio> #inclu…
A simple Gaussian elimination problem. Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 728 Accepted Submission(s): 241 Problem Description Dragon is studying math. One day, he drew a table with sev…
网络流 网络流是模仿水流解决生活中类似问题的一种方法策略,来看这么一个问题,有一个自来水厂S,它要向目标T提供水量,从S出发有不确定数量和方向的水管,它可能直接到达T或者经过更多的节点的中转,目前确定的是每条水管中水流的流向是确定的(单向),且每个水管单位时间内都有属于自己的水流量的上限(超过会爆水管),问题是求终点T单位时间内获得的最大水流量是多少?如下图: 1. 首先,我们用正常的思路去解决这个问题,对于上图的情况而言,我们可以先选择一条水流的路线1->2->4,而且我们得知1->2…
最大流EK和Dinic算法 EK算法 最朴素的求最大流的算法. 做法:不停的寻找增广路,直到找不到为止 代码如下: @Frosero #include <cstdio> #include <iostream> #include <cstring> #include <queue> #define INF 0x3f3f3f3f using namespace std; int n,m; int cap[202][202],flow[202][202],mf[2…
P3376 [模板]网络最大流( Edmonds-krap.Dinic.ISAP 算法) 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入格式 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行包含三个正整数ui.vi.wi,表示第i条有向边从ui出发,到达vi,边权为wi(即该边最大流量为wi) 输出格式 一行,包含一个正整数,即为该网络的最大流. 输入输出样例 输入 #1 复制 4 5 4 3 4 2 30 4…
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 t…