裸题不多说,在网络流的练习题里,你甚至可以使用暴力。

#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[最大流]的更多相关文章

  1. 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)

    P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...

  2. 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 < ...

  3. 洛谷——P2936 [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  4. 洛谷 P2936 [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  5. [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  6. 【luogu P2936 [USACO09JAN]全流Total Flow】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2936 菜 #include <queue> #include <cstdio> #i ...

  7. BZOJ3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 45  Solved: 27[Sub ...

  8. [USACO09JAN]Total Flow【网络流】

    Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N & ...

  9. Openvswitch原理与代码分析(5): 内核中的流表flow table操作

      当一个数据包到达网卡的时候,首先要经过内核Openvswitch.ko,流表Flow Table在内核中有一份,通过key查找内核中的flow table,即可以得到action,然后执行acti ...

随机推荐

  1. Redis(六):java里常用的redis客户端(Jedis和Redisson)

    Redis的各种语言客户端列表,请参见Redis Client.其中Java客户端在github上start最高的是Jedis和Redisson.Jedis提供了完整Redis命令,而Redisson ...

  2. Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect ...

  3. coreos 之flannel

    提要: coreos 中 flannel 工具是coreos 网络划分工具.通过flannel 划分子网并向etcd 注册网络信息.可以做到宿主机集群中容器间网络通信. 1. 启动etcd2 服务: ...

  4. 修复open-ssl漏洞,升级open-ssl版本

    升级openssl环境至openssl-1.0.1g 1.查看源版本 [root@zj ~]# openssl version -a OpenSSL 0.9.8e-fips-rhel5 01 Jul ...

  5. hadoop 出现FATAL conf.Configuration: error parsing conf file,异常

    FATAL conf.Configuration: error parsing conf file: com.sun.org.apache.xerces.internal.impl.io.Malfor ...

  6. python从安装与使用pip到入门

    官方下载地址:https://www.python.org/downloads/ 下载后直接安装就可以了 再配一下环境变量, cmd运行python -V (注意,这里是大写的V) 打开python跑 ...

  7. IOS开发之----异常处理

    本文转载至 http://blog.csdn.net/chenyong05314/article/details/7906593 转载自:http://blog.sina.com.cn/s/blog_ ...

  8. 玩家下线(GS部分)

    玩家下线,之前一直感觉这个过程有点复杂 else if (stat == link_stat::link_disconnected || stat == link_stat::link_connect ...

  9. inclusion_tag 看图

  10. async & await (转载)

    async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们 编程埋下了一些 ...