#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. 收集主机OS相关数据

    #!/usr/bin/ksh touch hostinfo$(date +%Y%m%d).csv filename=hostinfo$(date +%Y%m%d).csv >${filename ...

  2. 8.2 OSI模型

    OSI模型它是为了使不同的网络厂商.硬件厂商它们的系统能够良好的进行兼容,进行互连而提出来的,是由ISO(国际标准化组织在1979年公布的),它是现在的计算机网络领域的金科玉律.大家都认可的一个标准, ...

  3. 9.11NOIP模拟题

    NOIP模拟赛 by thmyl   题目名称 superman market Lemon_Soda 可执行文件名 superman market Lemon_Soda 输入文件 superman.i ...

  4. Java根据年度将数据分组

    现在有这么一组数据 code                   name                year 45615654           x1                      ...

  5. Oh,mygoddess

    很早的时候就看了这一道题目 , 当时不会做 , 现在 边听歌边写无压力 ........ 题意 : 光辉骑士 一直都在 迷宫的右上角 , 第一行给你迷宫的规格 , 下面是迷宫 "O" ...

  6. 【转】基于linux下的变量声明declare的用法

    转自:http://techcurtman.iteye.com/blog/1249512 declare 功能介绍:声明变量的属性,如果使用declare,后面没有任何参数,那么bash就会主动将所有 ...

  7. MVC系列学习(九)-DTO的使用

    本次学习用的数据库,如下 1.什么是DTO:DataTransferObject 即数据传输对象,服务端的客户端的通信,自动定义个小的实体类,里面只包含我们需要传输的属性 2.不用DTO会有什么问题 ...

  8. 把多种验证规则用到一个model上

    基于标记特性的Model验证,真的太棒了,与jquery validate结合后激情四射,有木有,一句话完成前后端验证.简直让人秒爱... 但是爱是爱了,生活中总会有些小摩擦,这不问题来了:看图中那个 ...

  9. 提高mysql千万级大数据SQL查询优化几条经验

    凯哥java                             微信号                             kaigejava 功能介绍                    ...

  10. C# 配置文件ini操作类

    // [ DllImport ( "kernel32" ) ] //private static extern long WritePrivateProfileString ( s ...