/*Dinic*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define maxn 210
#define inf 0x7fffffff
using namespace std;
int n,m,num,head[maxn],cur[maxn],dis[maxn];
struct node{
int u,v,flow,pre;
}e[maxn*];
void Add(int from,int to,int t){
e[num].u=from;
e[num].v=to;
e[num].flow=t;
e[num].pre=head[from];
head[from]=num++;
}
void Init(){
scanf("%d%d",&m,&n);
int u,v,t;
memset(head,-,sizeof(head));
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&t);
Add(u,v,t);Add(v,u,);
}
}
bool Bfs(){
memset(dis,-,sizeof(dis));
queue<int>q;
q.push();dis[]=;
while(!q.empty()){
int k=q.front();q.pop();
for(int i=head[k];i!=-;i=e[i].pre){
int v=e[i].v;
if(dis[v]!=-||!e[i].flow)continue;
q.push(v);dis[v]=dis[k]+;;
}
}
return dis[n]!=-;
}
int Dfs(int now,int lim){
if(!lim||now==n)return lim;
int r=;
for(int &i=cur[now];i!=-;i=e[i].pre){
int v=e[i].v,s=;
if(dis[v]==dis[now]+&&(s=Dfs(v,min(lim,e[i].flow)))){
e[i].flow-=s;r+=s;
e[i^].flow+=s;lim-=s;
}
if(lim==)break;
}
return r;
}
void Dinic(){
int ans=;
while(Bfs()){
memcpy(cur,head,sizeof(head));
ans+=Dfs(,0x7fffffff);
}
printf("%d\n",ans);
}
int main()
{
Init();
Dinic();
return ;
}

codevs 1993 草地排水 USACO的更多相关文章

  1. Codevs 1993 草地排水

    1993 草地排水 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地 ...

  2. codevs 1993草地排水

    1993 草地排水

  3. CODEVS——T 1993 草地排水 USACO

    http://codevs.cn/problem/1993/  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 De ...

  4. 模板题 codevs 1993 草地排水 想学习的请看链接

    不能再水的题了. Dinic算法,比EK更快. 想要学习请看链接   https://comzyh.com/blog/archives/568/ 并附上我的模板(其实和comzyh大神的一样) #in ...

  5. 【CodeVS】1993草地排水

    题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水 ...

  6. 【最大流】【CODEVS】1993 草地排水

    [算法]网络流-最大流(dinic) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html #include<cstdio> #includ ...

  7. AC日记——草地排水 codevs 1993

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 在农夫约翰的农场上,每 ...

  8. - > 网络流(【最大流】草地排水模板题)

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 在农夫约翰的农场上,每 ...

  9. codevs1993 草地排水(最大流)

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond   题目描述 Description 在农夫约翰的农场上,每逢下雨,Bes ...

随机推荐

  1. python学习笔记(一)元组,序列,字典

    python学习笔记(一)元组,序列,字典

  2. Mysql Explain 详解

    Mysql Explain 详解[强烈推荐] Mysql Explain 详解一.语法explain < table_name >例如: explain select * from t3 ...

  3. Java中遍历Map的几种方法

      转自: http://blog.csdn.net/wzb56/article/details/7864911 方法分为两类: 一类是基于map的Entry:map.entrySet(); 一类是基 ...

  4. BZOJ 1046 上升序列

    Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...

  5. 解决maven仓库有jar包但是maven程序无法下载仓库jar包

    话说,这个问题困扰了我两个多月了已经~~~ 后来发现不知道被谁动了,把我的仓库没有放到仓库组里面~~~ 用admin登录进去,默认密码是admin123,然后看截图操作吧. (记得删除你本地报错说** ...

  6. MVC---Case 1

    <!DOCTYPE html> <html lang="en"> <head> <title>Backbone.js, Requir ...

  7. CentOS 5升级Python版本(2.4>2.7)

    安装SALT时,需要这样作,公司有一批REDHAT5的,弄起来... 然后却是: Missing Dependency: python(abi) = 2.6 is needed by package ...

  8. bit、sbin、sfr、sfr16 区别分析

    1.bit 和 sbit 都是 C51 扩展的变量类型. bit 和 int char 之类的差不多,只不过 char=8 位, bit=1 位而已.都是变量,编译器在编译过程中分配地址.除非你指定, ...

  9. netstat详解

    Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Membershi ...

  10. Gvim一些基本配置

    介绍一些关于Gvim(windows 7 32位 Vim 7.4)的基本配置,除了特别说明,代码一律添加在安装目录下的_vimrc文件中. 1.取消自动备份,这行代码需要添加在 _vimrc文件中的b ...