[poj1273]Drainage Ditches(最大流)
解题关键:最大流裸题
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<queue>
#include<vector>
#define inf 0x3f3f3f3f
#define MAX_V 252
using namespace std;
typedef long long ll;
struct edge{int to,cap,rev;};//终点,容量,反向边
vector<edge>G[MAX_V];
int level[MAX_V],iter[MAX_V];
int n,m,s,t;
void add_edge(int from,int to,int cap){
G[from].push_back((edge){to,cap,(int)G[to].size()});
G[to].push_back((edge){from,,(int)G[from].size()-});
}
void bfs(int s){
memset(level,-,sizeof level);
queue<int>que;
level[s]=;
que.push(s);
while(!que.empty()){
int v=que.front();que.pop();
for(int i=;i<G[v].size();i++){
edge &e=G[v][i];
if(e.cap>&&level[e.to]<){
level[e.to]=level[v]+;
que.push(e.to);
}
}
}
} int dfs(int v,int t,int f){
if(v==t) return f;
for(int &i=iter[v];i<G[v].size();i++){
edge &e=G[v][i];
if(e.cap>&&level[v]<level[e.to]){
int d=dfs(e.to,t,min(f,e.cap));
if(d>){
e.cap-=d;
G[e.to][e.rev].cap+=d;
return d;
}
}
}
return ;
} int dicnic(int s,int t){
int flow=,f;
while(){
bfs(s);
if(level[t]<) return flow;
memset(iter,,sizeof iter);
while((f=dfs(s,t,inf))>){
flow+=f;
}
}
return flow;
} int main(){
int u,v,f;
while(scanf("%d%d",&m,&n)!=EOF){
memset(G,,sizeof G);
for(int i=;i<m;i++){
scanf("%d%d%d",&u,&v,&f);
add_edge(u,v,f);
}
s=,t=n;
int ans=dicnic(s,t);
printf("%d\n",ans);
}
return ;
}
[poj1273]Drainage Ditches(最大流)的更多相关文章
- poj-1273 Drainage Ditches(最大流基础题)
题目链接: Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67475 Accepted ...
- POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...
- POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)
http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...
- poj1273 Drainage Ditches (最大流板子
网络流一直没学,来学一波网络流. https://vjudge.net/problem/POJ-1273 题意:给定点数,边数,源点,汇点,每条边容量,求最大流. 解法:EK或dinic. EK:每次 ...
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- 2018.07.06 POJ1273 Drainage Ditches(最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...
- poj1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68414 Accepted: 2648 ...
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
随机推荐
- mathjax
MathJax.Hub.Typeset() method. This will cause the preprocessors (if any were loaded) to run over the ...
- putty screen
http://www.cnblogs.com/xupeizhi/archive/2013/05/20/3088779.html screen 会创建一个跑着shell的单一窗口 Ctrl+a d退出刚 ...
- HDU - 2701 Lampyridae Teleportae 【模拟】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2701 题意 有一个萤火虫会闪现 一个人 也会闪现 给出 这个人的起始位置 和他能够闪现的距离 然后依次 ...
- STM32 JTDO JREST复用为普通IO
一.开启AFIO的时钟(必须保证先打开AFIO,否则无效) RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 二.禁用JTAG,使能SWD GP ...
- 算法思考: poj 1969 Count on Canton
A - Count on Canton Time Limit:1000MS Memory Limit:30000KB ...
- STL+位运算的文件
1.queue 队列 queue的头文件是<queue>. 定义queue对象的示例代码如: queue<int>q; 队列内存放的是int类型的数 queue<dou ...
- 中美贸易战再次开启,世界两极化进程正在加快形成!..... Copyright: 1688澳洲新闻网 Read more at: https://www.1688.com.au/world/international/2018/06/17/369368/
中美贸易战再次开启,世界两极化进程正在加快形成! https://www.1688.com.au/world/international/2018/06/17/369368/
- c# 继承小结
本文意在巩固基础知识,并不是对其进行深入剖析,如若对各位高手没有什么作用,请绕过.本文为原创文,所有示例均是博主测试过的,欢迎大家批评指正,如有转载请标明出处,谢谢.继承.封装和多态是面向对象编程的重 ...
- matlab之fliplr()函数
fliplr 左右翻转矩阵 语法: B = fliplr(A) 将矩阵A的列绕垂直轴进行左右翻转 matabc 如果A是一个行向量,fliplr(A)将A中元素的顺序进行翻转. 如果A是一个列向量, ...
- Codeforces 900D Unusual Sequences:记忆化搜索
题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...