#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. 4.28 QBXT模拟赛

    NOIP2016提高组模拟赛 ——By wangyurzee7 中文题目名称 迷妹 膜拜 换数游戏 英文题目与子目录名 fans mod game 可执行文件名 fans mod game 输入文件名 ...

  2. [Apple开发者帐户帮助]九、参考(5)支持的功能(tvOS)

    tvOS应用程序可用的功能取决于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用程序组 相关域名   背景模式 数据保护 游戏中心     游戏控制器 HomeKit iCloud:Cl ...

  3. c++小游戏

    #include <iostream> using namespace std; double shengmingli=2000;//定义主角初始生命力 int gongjili=150; ...

  4. dialog的各类显示方法

    图1效果:该效果是当按返回按钮时弹出一个提示,来确保无误操作,采用常见的对话框样式. 代码: 创建对话框方法dialog() protected void dialog() {  AlertDialo ...

  5. matlab中增加Java VM 的堆空间(解决xml_io_tools出现的OutOfMemory问题)

    今天用MATLAB写程序,调用了xml_io_tools(很赞的一个xml读写工具包)中的函数,但是由于我要书写的文件比较大,5m左右,运行时不知道xml_io_tools中的哪一块超出了java中的 ...

  6. Codeforces Round #419

    A Karen and Morning 找最近的回文时间 模拟  往后推 判判就行 //By SiriusRen #include <bits/stdc++.h> using namesp ...

  7. ACM_绝对值排序

    Why Males And Females Apart? Time Limit: 2000/1000ms (Java/Others) Problem Description: In so many o ...

  8. 如何让win32 c++窗口不出现在任务栏

    把窗口作为某一个窗口的子窗口,然后设置WS_POPUP就可以了.使用CreateWindow时的第三个参数设置为WS_CHILD|WS_POPUP.

  9. UI开发模式对比:JSP、Android、Flex

    前一篇文章分析了Java平台下不同类型WEB框架对开发模式的影响,多数Java领域的WEB框架都是聚焦于服务端MVC的实现,这些框架对View的支持,通常是基于标准的JSP或类似JSP的模板技术如Fr ...

  10. CSS——层级

    层级问题:选中的盒子显示的效果并不完整,右边的边框并没有显示红色,原因是其右边的盒子压了它的边框. <!DOCTYPE html> <html lang="en" ...