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

#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. QTreeWidget里嵌套表格QTableView

    InformationPositionSubTableView::InformationPositionSubTableView(QStringList& columnNameList,QLi ...

  2. Laravel 5.4---后端数据分页和前端显示分页结果

    后端数据(Eloquent 模型)分页 事先建立好Eloquent 模型和Controller 还有 前台的View.可以参考我之前的文章:Laravel建站03--建立前台文章列表和文章详情 在co ...

  3. java 中的CountDownLatch

    直接使用thread可以使用thread和wait notify 实现顺序执行 线程池中可以使用CountDownLatch 进行顺序执行 package com.test; import java. ...

  4. java代码评审内容

    评审内容 u 工具检查 □  Eclipse警告 □  FindBug □  CheckStyle □  Jupiter □  Subclipse 或者Subversive u 代码注释内容(详细参考 ...

  5. mongodb的mongod.lock文件及oplog文件

    在mongodb的启动时,在数据目录下,会生成一个mongod.lock文件.如果在正常退出时,会清除这个mongod.lock文件,若要是异常退出,在下次启动的时候,会禁止启动,从而保留一份干净的一 ...

  6. IOS --支付宝SDK 分解讲解

    开发在手机端的时候(客户端),我们主要负责客户端(手机端)的开发,所以那些繁琐的到支付宝官网填写商户信息可以留给后台去弄,后台只要把: 1回调地址, 2app的ID, 3商户的私钥(privateKe ...

  7. java项目中的classpath到底是什么

    https://segmentfault.com/a/1190000015802324

  8. EasyDSS流媒体视频实时回传与录像管理解决方案

    一.背景 1.1 方案背景 随着互联网基础设施建设的不断完善和发展,带宽的不断提速,尤其是光纤入户,4G/5G/NB-IoT各种技术的大规模商用,视频在各行各业越来越受到重视,无论是传统的视频媒体转向 ...

  9. 怎么查看自己的IP地址?

    https://jingyan.baidu.com/article/63f2362816d56c0208ab3dd5.html 1.通过自己的电脑查看的是内部局域网的IP地址 2.通过网上查看的IP地 ...

  10. Dijkstra的堆优化

    先附上一个例题:P3371 [模板]单源最短路径 一眼扫去,最短路... spfa可行,但是今天的主题是Dijkstra: #include<iostream> #include<a ...