洛谷 P2936 [USACO09JAN]全流Total Flow】的更多相关文章

P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different…
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different size pipes connected in an appa…
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different size pipes connected in an appa…
题目链接:https://www.luogu.org/problemnew/show/P2936 菜 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 10000; const int inf = 1e9; int n, m, s,…
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different size pipes connected in an appa…
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different size pipes connected in an appa…
题 裸题不多说,在网络流的练习题里,你甚至可以使用暴力. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; template<typename T>inline :;} template<typename T>inline :;} template<typename T>inline T _min(T A,T…
P3128 [USACO15DEC]最大流Max Flow 题目描述 Farmer John has installed a new system of N-1N−1 pipes to transport milk between the NN stalls in his barn (2 \leq N \leq 50,0002≤N≤50,000), conveniently numbered 1 \ldots N1…N. Each pipe connects a pair of stalls,…
题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his barn (), conveniently numbered . Each pipe connects a pair of stalls, and all stalls are connected to each-other via paths of pipes. FJ is pumping milk…
题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his barn (), conveniently numbered . Each pipe connects a pair of stalls, and all stalls are connected to each-other via paths of pipes. FJ is pumping milk…
裸的树上差分 因为要求点权所以在点上差分即可 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; ; ; ,u[MAXN*],v[MAXN*],first[MAXN],next[MAXN*]; int cf[MAXN]; ]; int n,k; void addedge(int ux,int vx){ cnt++; u[cnt]=ux; v[cnt]=vx; n…
题意 题目链接 Sol 树上差分模板题 发现自己傻傻的分不清边差分和点差分 边差分就是对边进行操作,我们在\(u, v\)除加上\(val\),同时在\(lca\)处减去\(2 * val\) 点差分是对点操作,我们在\(u, v\)处加上\(val\),在\(lca\)和\(fa[lca]\)处减去\(val\) 就本题而言,属于点差分 #include<bits/stdc++.h> const int MAXN = 1e5 + 10; using namespace std; inline…
题目描述 \(FJ\)给他的牛棚的\(N(2≤N≤50,000)\)个隔间之间安装了\(N-1\)根管道,隔间编号从\(1\)到\(N\).所有隔间都被管道连通了. \(FJ\)有\(K(1≤K≤100,000)\)条运输牛奶的路线,第\(i\)条路线从隔间\(s_i\)运输到隔间\(t_i\).一条运输路线会给它的两个端点处的隔间以及中间途径的所有隔间带来一个单位的运输压力,你需要计算压力最大的隔间的压力是多少. 输入输出格式 输入格式: The first line of the input…
题目:https://www.luogu.org/problemnew/show/P3128 倍增求 lca 也写错了活该第一次惨WA. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ],dep[maxn],s[maxn],mx; bool vis[maxn]; struct N{ int to,nx…
https://www.luogu.org/problem/show?pid=3128 题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his barn (), conveniently numbered . Each pipe connects a pair of stalls, and all stalls are connected to each-…
###题目链接### 题目大意: 给你一棵树,k 次操作,每次操作中有 a  b 两点,这两点路上的所有点都被标记一次.问你 k 次操作之后,整棵树上的点中被标记的最大次数是多少. 分析: 1.由于数据太大,故可以采用树上差分中的点差分来做到 O(1)标记. 2.需要用 tarjan 离线找出两点间的 lca . 3.在树上点差分中,还需要找到 lca 的父亲节点.由于在 tarjan 求 lca 时,并查集中的 pre[lca] 并非一直指向的是 lca 的父亲节点,故需要再开一个 fa[]…
题目:https://www.luogu.org/problemnew/show/P3128 树上差分.用离线lca,邻接表存好方便. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,M=1e5+; ],nxt[M<<],ans; bool vis[N]; struct Ed{ ,):nxt(n),to(…
因为徐州现场赛的G是树上差分+组合数学,但是比赛的时候没有写出来(自闭),背锅. 会差分数组但是不会树上差分,然后就学了一下. 看了一些东西之后,对树上差分写一点个人的理解: 首先要知道在树上,两点之间只有一条路径.树上差分就是在树上用差分数组,因为是在树上的操作,所以要用到lca,因为对于两点a,b,从a到b这一条链就是a-->lca(a,b)-->b,这是一条链. 其次,树上差分的两种操作:一种是对点权的,另一种是对边权的. 对于点权: 在树上将路径的起点a+1和终点b+1,lca(a,b…
P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 <= F <= P) favorite pastures F_i of the P (1 <= P <= 500; 1 <= F_i <= P) total pastures (conveniently nu…
P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 题目描述 Wisconsin has had an earthquake that has struck Farmer John's farm! The earthquake has damaged some of the pastures so that they are unpassable. Remarkably, none of the cowpaths was damaged. As usual, t…
这道题问的是一群人要和另一群人合影,每个客人都有必须在场的人全部在场才能在场,每个客人给的有收入,但是邀请也需要支出,问最大收入? 我觉得可以总结为一类问题,就是有先决条件的网络流问题.看到费用和支出我本来以为是费用流问题,但是想着想着发现这道题似乎和费用流没什么关系.费用流的决策并不符合这里的题意.本来是想客人和主人连边,起点到客人,汇点到主人之间连上容量为客人需要主人陪的数量的边,跑一下dinic再遍历前向星检测就行了.然而开幕雷击发生了,这种做法只有60,怎么改也没能更高. 然后想了半天就…
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> #define N 200100 #define INF 100000000 using namespace std; int ecnt=1,vis[N],dist[N],n,m,S,T,ans,head[N]; deque <int> q; struct adj { int nxt,v,w,c; }e[N…
题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 <= F <= P) favorite pastures F_i of the P (1 <= P <= 500; 1 <= F_i <= P) total pastures (conveniently numbered 1..P) that compose Farmer…
题目描述 有 nn 件工作要分配给 nn 个人做.第 ii 个人做第 jj 件工作产生的效益为 c_{ij}cij​ .试设计一个将 nn 件工作分配给 nn 个人做的分配方案,使产生的总效益最大. 输入输出格式 输入格式: 文件的第 11 行有 11 个正整数 nn ,表示有 nn 件工作要分配给 nn 个人做. 接下来的 nn 行中,每行有 nn 个整数 c_{ij}cij​ ​​,表示第 ii 个人做第 jj 件工作产生的效益为 c_{ij}cij​ . 输出格式: 两行分别输出最小总效益…
题目描述 WW 公司有 mm 个仓库和 nn 个零售商店.第 ii 个仓库有 a_iai​ 个单位的货物:第 jj 个零售商店需要 b_jbj​ 个单位的货物. 货物供需平衡,即\sum\limits_{i=1}^{m}a_i=\sum\limits_{j=1}^{n}b_ji=1∑m​ai​=j=1∑n​bj​ . 从第 ii 个仓库运送每单位货物到第 jj 个零售商店的费用为 c_{ij}cij​ ​​ . 试设计一个将仓库中所有货物运送到零售商店的运输方案,使总运输费用最少. 输入输出格式…
1 #include<bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 const int maxn=5005; 5 const int inf=0x3f3f3f3f; 6 int tot,n,m,s,t,x,y,z,d[maxn]; 7 int adj[maxn],nex[maxn<<1],to[maxn<<1],w[maxn<<1],flow[maxn<<1]; 8…
题链: https://www.luogu.org/problemnew/show/P2934 题解: 最短路(树),可并堆(左偏堆),并查集. 个人感觉很好的一个题. 由于题目已经明确说明:从1点到每个点的最短路有且只有一条. 那么跑完最短路后,就可以得到一个最短路树,即每个点只有一个来源点. 然后来考虑,如果某一个u点无法从其最短路树上的father到达时,是个怎样的情况: 由于u无法从其父亲到达,所以如果还存在1到u的路径的话, 应该在其子树内(包括u),存在一个v点,与子树外的某个节点x…
https://www.luogu.org/problem/show?pid=2934 题目描述 Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as each one walks from the barn (conveniently located at pasture_1) to the other fields, with cow_i traveling to…
题目链接 题意概述:把正整数n分为m个正整数,m个正整数中不允许出现复数个非1的正整数,保证所有小于n的正整数都可以用一部分正整数的和表示,并且使m尽量小. 这道题不知道为啥bzoj上没有要求输出方案,导致我把bzoj的程序粘到洛谷上瞬间全wa. 思想还是非常简单的,第一个钱袋装n/2个金币,第二个装n/2/2个金币,第三个…… 这样可以用和的形式表示任意小于n的正整数. 显然这样是最优解,而且基于不断除2得出的答案个数为log2n. #include<cstring> #include<…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5120 https://www.luogu.org/problemnew/show/P4003 神奇的费用流建图: 首先,网格图,相邻之间有关系,所以先二分染色一下: 然后发现问题就是染色后黑白点之间要完美匹配插头: 所以可以考虑把旋转通过带一些代价变成插头方向的变化: 把一个格子拆成上下左右四个点,分类讨论,连边即可: 然而一开始连边竟然写了100多行...然后T了: 看了看题解代码,突然…