P2936(BZOJ3396) [USACO09JAN]全流Total Flow[最大流]
裸题不多说,在网络流的练习题里,你甚至可以使用暴力。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>inline char MIN(T&A,T B){return A<B?A=B,:;}
template<typename T>inline char MAX(T&A,T B){return A>B?A=B,:;}
template<typename T>inline T _min(T A,T B){return A<B?A:B;}
template<typename T>inline T _max(T A,T B){return A>B?A:B;}
template<typename T>inline T read(T&x){
x=;char c;while(!isdigit(c=getchar()))if(isalpha(c))return x=(int)c;
while(isdigit(c))x=(x<<)+(x<<)+(c^),c=getchar();return x;
}
const int N=+,INF=0x3f3f3f3f;
int w[N<<],v[N<<],Next[N<<],Head[N],cur[N],dis[N],tot=;
inline void Addedge(int x,int y,int z){
v[++tot]=y,Next[tot]=Head[x],Head[x]=tot,w[tot]=z;
v[++tot]=x,Next[tot]=Head[y],Head[y]=tot,w[tot]=;
}
#define y v[j]
inline char bfs(){
queue<int> q;memset(dis,,sizeof dis),dis['A']=,q.push('A');
while(!q.empty()){
int x=q.front();q.pop();
for(register int j=Head[x];j;j=Next[j])if(w[j]&&!dis[y]){
dis[y]=dis[x]+,q.push(y);
if(y=='Z')return ;
}
}
return ;
}
int dinic(int x,int flow){
if(x=='Z'||!flow)return flow;
int rest=flow,k;
for(register int j=cur[x];j&&rest;cur[x]=j,j=Next[j])if(w[j]&&dis[y]==dis[x]+){
if(!(k=dinic(y,_min(rest,w[j]))))dis[y]=;
rest-=k,w[j]-=k,w[j^]+=k;
}
return flow-rest;
}
#undef y
int m,x,y,z,ans; int main(){//freopen("tmp.in","r",stdin);freopen("tmp.out","w",stdout);
read(m);
for(register int i=;i<=m;++i)read(x),read(y),read(z),Addedge(x,y,z);
while(bfs()){
for(register int i='A';i<='z';++i)cur[i]=Head[i];
ans+=dinic('A',INF);
}
printf("%d\n",ans);
return ;
}
P2936(BZOJ3396) [USACO09JAN]全流Total Flow[最大流]的更多相关文章
- 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)
P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...
- AC日记——[USACO09JAN]全流Total Flow 洛谷 P2936
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 洛谷——P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 洛谷 P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 【luogu P2936 [USACO09JAN]全流Total Flow】 题解
题目链接:https://www.luogu.org/problemnew/show/P2936 菜 #include <queue> #include <cstdio> #i ...
- BZOJ3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 45 Solved: 27[Sub ...
- [USACO09JAN]Total Flow【网络流】
Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N & ...
- Openvswitch原理与代码分析(5): 内核中的流表flow table操作
当一个数据包到达网卡的时候,首先要经过内核Openvswitch.ko,流表Flow Table在内核中有一份,通过key查找内核中的flow table,即可以得到action,然后执行acti ...
随机推荐
- cmake学习之-configure_file
一.系统版本 cmake version: 3.5.2 系统版本: Ubuntun 16.04 cmake docment: 3.14.4 最后更新: 2019-05-30 二.指令说明 config ...
- matlab2017b linux版分享
链接:https://pan.baidu.com/s/1smrTkFN 密码:cvb3 下载后请点关注并点赞,谢谢支持.
- leetCode 84.Largest Rectangle in Histogram (最大矩形直方图) 解题思路和方法
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- java中BigDecimal的学习
干着java的活,但是看的都是一些偏底层的东西(或者我根本就没有看),有点荒废了java的学习. 最近一直在用到一个类是BigDecimal,但都是模棱两可地在那儿用,并没有深入研究这个类的细节,感觉 ...
- 深入Asyncio(四)Coroutines
Coroutines asyncio在3.4版本添加到Python中,但通过async def和await关键字创建coroutines的语法是3.5才加入的,在这之前,人们把generators当作 ...
- 15 redis 之 aof恢复与rdb服务器间迁移
三:常见的问题 BGREWRITEAOF 后台进程重写AOF BGSAVE 后台保存rdb快照 SAVE 保存rdb快照 LASTSAVE 上次保存时间 Slaveof master-Host por ...
- Mybatis资料
1. 入门案例 https://www.cnblogs.com/xdp-gacl/p/4261895.html 2. 详细笔记 以及配套视频教程: 笔记:https://blog.csdn.net/S ...
- [Python]Pip换源以及设置代理
Install python package with proxy sudo pip install python-magic --proxy=https://your-proxy.com 2.No ...
- 【题解】kth异或和/魔改版线性基
[题解]魔改版线性基 魔改版线性基解决此类问题. 联系线性空间的性质,我们直接可以构造出这样的基: \[ 100000 \\ 010000 \\ 000010 \\ 000001 \] 使得每个基的最 ...
- table表格隔行变色
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...