#include<stdio.h>

#include<string.h>

#include<queue>

#include<iostream>

using namespace std;

#define N 300

#define inf 2000000000

int map[N][N];

int start,end,flow[N],pre[N];

int bfs() {

   int i,now;

  memset(pre,-1,sizeof(pre));

   flow[start]=inf;

   queue<int>q;

   while(!q.empty())

  q.pop();

   q.push(start);

   while(!q.empty()) {

   now=q.front();

   q.pop();

   for(i=1;i<=end;i++)

  if(i!=start&&pre[i]==-1&&map[now][i]) {

  flow[i]=flow[now]<map[now][i]?flow[now]:map[now][i];

  q.push(i);

  pre[i]=now;

  }

   }

   if(pre[end]==-1)return -1;

   return flow[end];

}

int ek(){

int maxflow=0,now,step,pr;

while((step=bfs())!=-1) {

   maxflow+=step;

   now=end;

   while(now!=start) {

  pr=pre[now];

  map[pr][now]-=step;

       map[now][pr]+=step;

  now=pr;

   }

}

return maxflow;

}

int main() {

int n,m,a,b,c;

    while(scanf("%d%d",&n,&m)!=EOF) {

memset(map,0,sizeof(map));

start=1;end=m;

while(n--) {

scanf("%d%d%d",&a,&b,&c);

map[a][b]+=c;

}

printf("%d\n",ek());

}

return 0;

}

hdu 1532&&poj1273 基础最大流的更多相关文章

  1. hdu 1532 Drainage Ditches (最大流)

    最大流的第一道题,刚开始学这玩意儿,感觉好难啊!哎····· 希望慢慢地能够理解一点吧! #include<stdio.h> #include<string.h> #inclu ...

  2. Drainage Ditches (HDU - 1532)(最大流)

    HDU - 1532 题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少? 题解:最大流模板题. #include <iostream> #include <algor ...

  3. HDU 1532||POJ1273:Drainage Ditches(最大流)

    pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. HDU 1532 Drainage Ditches(最大流 EK算法)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...

  5. HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...

  6. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)

    Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...

  7. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

  8. HDU 1532 --&&-- POJ1273 dinic 算法

    学长的代码#include<stdio.h> #include<string.h> #include<queue> #include<algorithm> ...

  9. HDU 1532.Drainage Ditches-网络流最大流

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. bzoj4756

    http://www.lydsy.com/JudgeOnline/problem.php?id=4756 水题一枚...但是我写了一个小时...手贱打反查不出来... 就是每次线段树合并,先把自己的儿 ...

  2. Oracle查询列重命名

    select count(*) 呼入量 from crm_cisco_call_detail

  3. java线程系列---Runnable和Thread的区别 (转载)

    转自:http://blog.csdn.net/wwww1988600/article/details/7309070 在java中可有两种方式实现多线程,一种是继承 Thread类,一种是实现Run ...

  4. 洛谷P1341 无序字母对(欧拉回路)

    P1341 无序字母对 题目描述 给定n个各不相同的无序字母对(区分大小写,无序即字母对中的两个字母可以位置颠倒).请构造一个有n+1个字母的字符串使得每个字母对都在这个字符串中出现. 输入输出格式 ...

  5. phonegap+cordova+ionic调用原生API

    上一篇博客讲了phonegap+cordova+ionic的环境搭建,今天再来分享一篇cordova调用原生API的文章.从技术角度上来讲,这并不是很难,只是有些细节要是没有注意,或者某些步骤不知道的 ...

  6. @RequestParam 和 @RequestBody 接受的时间格式

    这两个接受的时间格式不相同 首先看一下他们的区别 @RequestParam用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容.(Ht ...

  7. ACM_蛋糕小王子铁头娃

    Problem Description: 铁头娃制作了很多蛋糕,想分给他的小伙伴们,他的小伙伴很喜欢铁头娃做的蛋糕,每个人都想分到最多蛋糕 铁头娃想到了一个头铁主意:先给小伙伴们从1到N编号,在1-N ...

  8. 海量文本信息查Top-k

    问题描述: 有1千万条短信,一条一行,有重复.在5分钟之内,找出重复出现的前10条. 方案一: 1.分组进行边扫描边建散列表.建立哈希表,使用头,尾和中间随便两个字节作为Hash Code, 插入到H ...

  9. 初步认识kafka

    Kafka是用于日志处理的分布式消息队列,Kafka使用scala语言开发的. 各个开源分布式处理系统Cloudera.Apache Storm.Spark都支持与Kafka集成.其日志处理的一个场景 ...

  10. Java——Spring注解

    Spring常用注解使用注解来构造IoC容器用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan bas ...