POJ 1273 Drainage Ditches【最大流】
题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去
看的紫书的最大流,还不是很理解,照着敲了一遍
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
int n,m,M; struct Edge{
int from,to,cap,flow;
Edge(int u,int v,int c,int f) :from(u),to(v),cap(c),flow(f) {}
}; vector<Edge> edges;//存边
vector<int> G[maxn];//邻接表
int a[maxn];//到起点i的可改进量
int p[maxn];//最短 路树上p的入弧编号 void init(){
for(int i=;i<n;i++) G[i].clear();
edges.clear();
} void addedges(int from,int to,int cap){
edges.push_back(Edge(from,to,cap,));
edges.push_back(Edge(to,from,,));//反向弧
m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} int Maxflow(int s,int t){
int flow=;
for(;;){
memset(a,,sizeof(a));
queue<int> q;
q.push(s);
a[s]=INF;
while(!q.empty()){
int x=q.front();q.pop();
for(int i = ;i < G[x].size(); i++){
Edge& e = edges[G[x][i]];
if(!a[e.to]&&e.cap>e.flow){
p[e.to] = G[x][i];
a[e.to] = min(a[x], e.cap-e.flow);
q.push(e.to);
}
}
if(a[t]) break;
}
if(!a[t]) break;
for(int u = t;u !=s ;u=edges[p[u]].from){
edges[p[u]].flow+=a[t];
edges[p[u]^].flow-=a[t];
}
flow+=a[t];
}
return flow;
} int main(){
while(scanf("%d %d",&M,&n)!=EOF){
init();
for(int i=;i<M;i++){
int u,v,c;
scanf("%d %d %d",&u,&v,&c);
u--;v--;
addedges(u,v,c);
}
printf("%d\n",Maxflow(,n-));
}
return ;
}
寒假的cf就遇到过最大流的题目,当时不会而且还没有学
现在又遇到了,不能再这样了,先学一点点先吧-----------------------
gooooooooooooooo------------
加油====================
POJ 1273 Drainage Ditches【最大流】的更多相关文章
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- POJ 1273 Drainage Ditches 最大流
这道题用dinic会超时 用E_K就没问题 注意输入数据有重边.POJ1273 dinic的复杂度为O(N*N*M)E_K的复杂度为O(N*M*M)对于这道题,复杂度是相同的. 然而dinic主要依靠 ...
- POJ 1273 Drainage Ditches | 最大流模板
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...
- POJ 1273 Drainage Ditches(最大流Dinic 模板)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n, ...
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1273 Drainage Ditches (网络最大流)
http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- poj 1273 Drainage Ditches【最大流入门】
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63924 Accepted: 2467 ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
随机推荐
- 什么时候使用try-catch
上篇文章叙述了try-catch的效率问题,以及StackOverflow上各路大神们指出使用try-catch应该注意的一些问题. 这篇文章作为补充,转述下StackOverflow上各路大神对于何 ...
- Android饼图的简单实现
1.简单的实现效果图: 2.自定义View的实现 package myapplication.com.myapp.view; import android.content.Context; impor ...
- DataReader相关知识点
C#中提供的DataReader可以从数据库中每次提取一条数据. 1. 获取数据的方式[1]DataReader 为在线操作数据, DataReader会一直占用SqlConnection连接,在其获 ...
- C语言-统计数字、字母、特殊字符
Action() { //统计字符019aBcd8***,4,4,3 int i,z,t; char *str="019aBcd8***"; fun_Count(str,i,z,t ...
- GCD与dispatch_group总结
GCD 可以看作是集合类的操作: 集合是queue,元素是block: 集合只能添加对象,删除对象由系统完成. 同理,NSOperationQueue也可以看作是一个集合管理器. dispatch_g ...
- Type system-Type checking
类型系统的属性: 1.结构属性: 2.规则属性:类型系统定义了一套规则(内部数据的访问规则.函数的访问规则.类型的比较与转化规则),以供编译和运行时进行检查. In programming langu ...
- SpringMVC(六)POJO类作为 @RequestMapping方法的参数
Command or form objects to bind request parameters to bean properties (via setters) or directly to f ...
- TF基础3
批标准化 批标准化(batch normalization,BN)是为了克服神经网络层数加深导致难以训练而诞生的.深度神经网络随着深度加深,收敛会越来越慢,会导致梯度弥散问题(vanishing gr ...
- day06-1 与用户交互以及格式化输出
目录 Python的与用户交互 Python2的input和raw_input(了解) 格式化输出 占位符 format函数格式化字符串 f-string格式化(方便) Python的与用户交互 in ...
- Pyhton学习——Day31
# 服务端和接收端的send和reve没有任何关系,只与协议之间有关系# 应用程序产生的数据一定会交给操作系统,并由操作系统往外发送# 发送端什么时候会清空自己的内存?# 收到接收端的ACK响应以后才 ...