codevs 1993 草地排水 USACO
/*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的更多相关文章
- Codevs 1993 草地排水
1993 草地排水 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地 ...
- codevs 1993草地排水
1993 草地排水
- CODEVS——T 1993 草地排水 USACO
http://codevs.cn/problem/1993/ 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 De ...
- 模板题 codevs 1993 草地排水 想学习的请看链接
不能再水的题了. Dinic算法,比EK更快. 想要学习请看链接 https://comzyh.com/blog/archives/568/ 并附上我的模板(其实和comzyh大神的一样) #in ...
- 【CodeVS】1993草地排水
题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水 ...
- 【最大流】【CODEVS】1993 草地排水
[算法]网络流-最大流(dinic) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html #include<cstdio> #includ ...
- AC日记——草地排水 codevs 1993
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- - > 网络流(【最大流】草地排水模板题)
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- codevs1993 草地排水(最大流)
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bes ...
随机推荐
- MySQL账号授权操作
Mysql权限控制 - 允许用户远程连接 设置mysql root密码: mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = P ...
- Hadoop 学习笔记 (八) hadoop2.2.0 测试环境部署 及两种启动方式
1基本流程步骤1:准备硬件(linux操作系统)步骤2:准备软件安装包,并安装基础软件(主要是JDK)步骤3:修改配置文件步骤4:分发hadoop步骤5:启动服务步骤6:验证是否启动成功!2硬件配置要 ...
- Deferred
http://blog.allenm.me/2012/01/jquery_deferred_promise_method/ http://www.ruanyifeng.com/blog/2011/08 ...
- bcb 如何在DLL中捕捉系统级异常
http://topic.csdn.net/t/20031023/09/2385627.html -------------------------------------------------- ...
- 【HDOJ】2645 find the nearest station
裸BFS. /* 2645 */ #include <iostream> #include <queue> #include <cstdio> #include & ...
- MongoDB主从配置
master的配置 # cat mongod.conf dbpath = /app/sinova/mongodata/db #指定数据库目录 logpath = /app/sin ...
- HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)
Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In ...
- 动态规划——G 回文串
G - 回文串 Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- cf703A Mishka and Game
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- [Locked] Palindrome Permutation I & II
Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...