解题关键:最大流裸题

#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(最大流)的更多相关文章

  1. poj-1273 Drainage Ditches(最大流基础题)

    题目链接: Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67475   Accepted ...

  2. POJ-1273 Drainage Ditches 最大流Dinic

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...

  3. POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)

    http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...

  4. poj1273 Drainage Ditches (最大流板子

    网络流一直没学,来学一波网络流. https://vjudge.net/problem/POJ-1273 题意:给定点数,边数,源点,汇点,每条边容量,求最大流. 解法:EK或dinic. EK:每次 ...

  5. poj1273 Drainage Ditches Dinic最大流

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 76000   Accepted: 2953 ...

  6. Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )

    题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...

  7. 2018.07.06 POJ1273 Drainage Ditches(最大流)

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...

  8. poj1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68414   Accepted: 2648 ...

  9. poj 1273 Drainage Ditches 最大流入门题

    题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...

随机推荐

  1. Linux基础系列:常用命令(7)_正则表达式

    一.环境边量 每个用户登录shell需要执行的四个文件 /etc/profile /home/egon/.bashrc_profile /home/egon/.bashrc /etc/bashrc 非 ...

  2. UIImageView 获取图片的 宽 高

    该文章纯属这两天开发的经验之谈 并且也是平常没注意 这回发现的一个小方法 并且很实用 在开发中 提高了很大的效率 更加符合高保真的要求 通常 美术 切的一些图片 需要 :1还原的 现在 我们一般支持i ...

  3. windows下安装pywin32报错:close failed in file object destructor:sys.excepthook is missing lost sys.stderr

    今晚要写搜索引擎作业,搭scrapy环境,遇到了下面问题: windows下安装pywin32报错:close failed in file object destructor:sys.excepth ...

  4. CommonJS、AMD与CMD

    自从有了模块,我们可以更方便地使用别人的代码,想要什么功能,就加载什么模块.但是,这样做有一个前提,那就是大家必须以同样的方式编写模块,否则你有你的写法,我有我的写法,岂不是乱了套! 于是下面三个模块 ...

  5. python 特征选择 绘图 + mine

    demo代码: # _*_coding:UTF-8_*_ import numpy as np import sys import pandas as pd from pandas import Se ...

  6. 计算机_网络_01_配置IE代理

    一.配置代理 1.打开代理设置 打开chrome浏览器设置->高级设置->系统->打开代理设置 2.打开局域网设置 Internet属性->连接->局域网设置 3.配置代 ...

  7. Mybatis_笔记_01_逆向工程

    通过Mybatis逆向工程,可以从数据库中的表自动生成pojo.mapper映射文件和mapper接口 此处暂存怎么使用逆向工程,原理以后再探讨 工程结构 要修改的地方:generatorConfig ...

  8. Javascript-- jQuery事件篇(3)

    on()的多事件绑定 之前学的鼠标事件,表单事件与键盘事件都有个特点,就是直接给元素绑定一个处理函数,所有这类事件都是属于快捷处理.翻开源码其实可以看到,所有的快捷事件在底层的处理都是通过一个&quo ...

  9. javaScript-基础篇(一)

    1.如何插入JS 使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<scri ...

  10. 【BZOJ 4709】柠檬 斜率优化dp+单调栈

    题意 给$n$个贝壳,可以将贝壳分成若干段,每段选取一个贝壳$s_i$,这一段$s_i$的数目为$num$,可以得到$num^2\times s_i$个柠檬,求最多能得到几个柠檬 可以发现只有在一段中 ...