#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. MSP430:管脚的第二功能选择

    之前在使用PWM,AD时候用到过第二功能,不过都是copy没有注意过PXSEL究竟怎么设置,今天在设置晶振管脚时候遇到了麻烦,细致看了一下其实很简单,在SPEC的最后详细讲了每个管脚如何设置为其他功能 ...

  2. jsp简单学习总结

    以下均为jsp页面 1:<jsp:include page="index.jsp"/>相当于嵌入一个页面.还有一种是<frame src="main_l ...

  3. Java中的自定义注解

    ## 元注解 要声明一个注解, 我们需要元注解, 元注解是指注解的注解,包括@Retention, @Target, @Document, @Inherited. @Retention 注解的保留位置 ...

  4. windows怎么进如debug调试

    主要说一下64位Win7使用debug程序的方法 首先你要下载一个DOSBOX程序 这个程序是一个dos模拟器 这个程序的制作目的是运行经典的DOS游戏 -.- 下载地址:http://www.dos ...

  5. python常见的加密方式

    1.前言 我们所说的加密方式都是对二进制编码的格式进行加密,对应到python中,则是我妈们的bytes. 所以当我们在Python中进行加密操作的时候,要确保我们的操作是bytes,否则就会报错. ...

  6. 关于BUG

    1.BUG的理解 2.提高BUG report的技巧

  7. scala的Map

    package com.test.scala.test object MapTest { def main(args: Array[String]): Unit = { //定义一个不可变的map v ...

  8. Spring boot中的定时任务(计划任务)

    从Spring3.1开始,计划任务在Spring中实现变得异常的简单.首先通过配置类注解@EnableScheduling来开启对计划任务的支持,然后再要执行的计划任务的方法上注释@Scheduled ...

  9. Python--10、进程知识补充

    守护进程 基于进程启动的子进程,会和主进程一起结束.主进程结束的依据是程序的代码执行完毕. #创建守护进程p=Process(task) p.daemon = True p.start() 子进程需要 ...

  10. 关于jquery $.browser 报错问题

    在调用 jquery 插件时,出现$.browser 报错,原来是jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version 等属性, 取而代之的是 $.su ...