HDU - 1532

题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少?

题解:最大流模板题。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 0x3ffffff;
const int maxn = 205;
int gra[maxn][maxn];
int flow[maxn];
int path[maxn];
int n,m; int bfs(int s, int e)
{
queue<int>q;
int t;
memset(path,-1,sizeof(path));
memset(flow,0,sizeof(flow));
path[s] = 0;
flow[s] = INF;
q.push(s);
while(!q.empty()){
t = q.front();
q.pop();
if(t == e) break;
for(int i = 1; i <= m; i ++)
{
if(i != s && gra[t][i] && path[i] == -1)
{
flow[i] = flow[t] < gra[t][i] ? flow[t] : gra[t][i];
path[i] = t;
q.push(i);
}
}
}
if(path[e] == -1)
return -1;
else return flow[e];
} int EK(int s, int e){
int maxflow = 0;
int pre, now, step;
while((step = bfs(s,e))!= -1){
maxflow += step;
now = e;
while(now != s){
pre = path[now];
gra[pre][now] -= step;
gra[now][pre] += step;
now = pre;
}
}
return maxflow;
}
int main()
{ int u,v,c;
while(~scanf("%d%d",&n,&m)){
memset(gra,0,sizeof(gra));
for(int i = 1; i <= n; i ++)
{
scanf("%d %d %d", &u,&v,&c);
gra[u][v] += c;
}
int ans = EK(1,m);
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. 推荐一篇关于java 学习的文章,感觉写的很不错
  2. vim 配置
  3. Spring学习总结(三)——Spring实现AOP的多种方式
  4. python中from module import * 的一个陷阱
  5. python设计模式之--单例模式
  6. NDK学习二: NDK目录结构
  7. 制作、解析带logo的二维码
  8. Spring+MyBatis多数据源配置实现
  9. How-to: disable the web-security-check in Chrome for Mac
  10. android:ToolBar详解(手把手教程)
  11. JavaScript---闭包和作用域链
  12. Jquery datatables 重载数据方法
  13. MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途
  14. BackgroundWorker 后台进程控制窗体label、richtextbook内容刷新
  15. 如何在程序退出的时候清除activity栈
  16. LINQ To SQL在N层应用程序中的CUD操作、批量删除、批量更新
  17. CF368 D - Persistent Bookcase
  18. 初涉IPC,了解AIDL的工作原理及使用方法
  19. 报错:Heartbeating to master:7182 failed.
  20. 【python】Django自定义模板函数

热门文章

  1. springboot中使用验证码kaptcha
  2. Java Web 深入分析(2) DNS
  3. [转载]详解网络传输中的三张表,MAC地址表、ARP缓存表以及路由表
  4. VBA变量(七)
  5. docker系列五之数据卷(volumn)
  6. vue 2.0+ 怎么写本地接口获取数据
  7. 原生js上传图片遇到的坑(axios封装)
  8. Sliverlight/WPF 样式使用方法
  9. Linux命令——mkdir、rmdir
  10. hive中使用spark执行引擎的常用参数