- > 网络流(草地排水)
网络流(Dinic(模板))
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16467 Accepted Submission(s): 7823
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define MAXN 300
#define INF 9999999
using namespace std;
int N,M,map[MAXN][MAXN],a,b,f,maxflow,pre[MAXN];
void flow(int start,int end){
while(1){
queue<int>q;
/*while(!q.empty())
q.pop();*/
int minflow=INF;
q.push(1);
memset(pre,0,sizeof(pre));
while(!q.empty()){
int u=q.front();
q.pop();
if(u==end) break;
for(int i=1;i<=M;i++)
if(map[u][i]&&!pre[i]){
pre[i]=u;
q.push(i);
}
}
if(pre[end]==0) break;
for(int i=end;i!=start;i=pre[i])
minflow=min(minflow,map[pre[i]][i]);
for(int i=end;i!=start;i=pre[i]){
map[pre[i]][i]-=minflow;
map[i][pre[i]]+=minflow;
}
maxflow+=minflow;
}
}
int main(){
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>a>>b>>f;
map[a][b]+=f;
}
maxflow; //最大流
flow(1,M);
cout<<maxflow;
}
- > 网络流(草地排水)的更多相关文章
- [网络流]Drainage Ditches(草地排水)
Drainage Ditches(草地排水) 题目描述 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰 ...
- - > 网络流(【最大流】草地排水模板题)
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- 题解 【USACO 4.2.1】草地排水
[USACO 4.2.1]草地排水 Description 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫 ...
- 草地排水 洛谷P2740 最大流 入门题目
草地排水 洛谷P2740 最大流入门题目 题意 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一 ...
- 【codevs1993】草地排水 最大流
[codevs1993]草地排水 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段 ...
- 【USACO】草地排水
Drainage Ditches 草地排水 usaco 4.2.1描述在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一 ...
- Codevs 1993 草地排水
1993 草地排水 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地 ...
- codevs 1993草地排水
1993 草地排水
- AC日记——草地排水 codevs 1993
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- codevs1993 草地排水(最大流)
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bes ...
随机推荐
- C - GCD LCM
Description The GCD of two positive integers is the largest integer that divides both the integers w ...
- JDBC和数据库连接池
JDBC是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成. ● JDBC ● C3P0 ● DRUID 一.JDBC ...
- redis学习-字典
1.字典作用 实现数据库键空间(key space): 用作 Hash 类型键的底层实现之一: 2.字典实现的数据结构 typedef struct dict { // 特定于类型的处理函数 dict ...
- EF CodeFirst 不得不说的Where与OrderBy
先来聊上5毛钱的“排序” Code: using (ApplicationDbContext Db=new ApplicationDbContext()) { var res = Db.Threes. ...
- Ps 快捷键全解
一.工具箱(多种工具共用一个快捷键的可同时按[Shift]加此快捷键选取)矩形.椭圆选框工具 [M]移动工具 [V]套索.多边形套索.磁性套索 [L]魔棒工具 [W]裁剪工具 [C]切片工具.切片选择 ...
- C++ 模板template和template
原文链接:https://blog.csdn.net/skyleung/article/details/42195509 template<class T>和template<typ ...
- Spring Boot 创建hello world项目
Spring Boot 创建hello world项目 1.创建项目 最近在学习Spring Boot,这里记录使用IDEA创建Spring Boot的的过程 在1出勾选,选择2,点击Next 这里填 ...
- BZOJ 1176: [Balkan2007]Mokia KDtree
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin), ...
- for循环,isinstance() 函数
#isinstance()的运用 #练习: 求值总和以及平均值. str_list = [1,2,3,4,5,6,'a',7,8,9,'b',10,'c'] my_tal = 0 my_var = 0 ...
- Codeforces Round #470 Div. 2题解
A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...