#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. MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式。

    原文链接:https://www.muhanxue.com/essays/2015/01/8623699.html MVC web api 返回JSON的几种方式 1.在WebApiConfig的Re ...

  2. Akka源码分析-故障恢复

    Actor故障恢复是akka中非常重要的内容,在之前的博客中虽然有介绍,但都是杂糅在其他知识点的细节中,本博客将单独介绍这一部分的故障恢复.为了简化分析的单独,本文只研究用户的actor故障恢复的步骤 ...

  3. Akka源码分析-Actor创建(续)

    在上一遍博客中,我们已经分析了actor创建的大致过程,但只是涉及到了Dipatcher/Mailbox/ActorCell/InternalActorRef等对象的创建,并没有介绍我们自定义的继承A ...

  4. Vue使用html2canvas将页面转化为图片

    需求是微信端将页面截屏之后保存到本地,使用了html2canvas插件 先引入插件 npm install --save html2canvas 之后在你所需要使用的页面引入 import html2 ...

  5. JavaScript--显示和隐藏(display属性)

    网页中经常会看到显示和隐藏的效果,可通过display属性来设置. 语法: Object.style.display = value 注意:Object是获取的元素对象,如通过document.get ...

  6. BZOJ 2178 Simpson积分

    思路: 我发现能用Simpson积分水的题  好像都是裸题诶233333 //By SiriusRen #include <bits/stdc++.h> using namespace s ...

  7. servlet的多线程并发问题

    package gz.itcast.e_thread; import java.io.IOException; import javax.servlet.ServletException; impor ...

  8. Centos6.6 安装基于系统认证的vsftp服务

    一.介绍 vsftp是一款文件服务器软件,在文件共享,代码更新,文件备份中也是经常用到,以下是基本安装环境: 1)CentOS6.6 2)vsftpd-2.2.2 二.安装 $ yum install ...

  9. (转)Java任务调度框架Quartz入门教程指南(二) 使用job、trigger、schedule调用定时任务

    http://blog.csdn.net/zixiao217/article/details/53044890 读完第一节,我们已经对Quartz有了一个大体的认识,它可以定时帮我们执行一些处理程序, ...

  10. 用C#在Visual Studio写Javascript单元测试(Firefox内核)

    引用nuget包: 注意:Geckofx45 nuget包必须是最后引用,否则初始化会出错 编写JsRunner using Gecko; using System; using System.Col ...