hdu3549 最大流
#include<stdio.h>
#include<string.h>
#include<queue>
#define MAXN 1010
using namespace std;
int map[MAXN][MAXN],n,dis[MAXN];
int min(int x,int y)
{return x<y?x:y;}
int bfs()
{
int i,j;
queue<int>q;
memset(dis,-,sizeof(dis));
dis[]=;
q.push();
while(!q.empty())
{
int t=q.front();
q.pop();
for(i=;i<=n;i++)
{
if(map[t][i]&&dis[i]<)
{
dis[i]=dis[t]+;
q.push(i);
}
}
}
if(dis[n]>)
return ;
return ;
}
int dfs(int u,int low)
{
int i,j,a;
if(u==n)
return low;
for(i=;i<=n;i++)
{
if(map[u][i]&&dis[i]==dis[u]+)
{
a=dfs(i,min(map[u][i],low));
if(a<=)continue;
map[u][i]-=a;
map[i][u]+=a;
return a;
}
}
return ;
}
int main()
{
int t,ff=,i,j,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(map,,sizeof(map));
for(i=;i<m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
map[x][y]+=z;
}
int ans=;
while(bfs())
{
while()
{
int a=dfs(,);
if(!a)break;
ans+=a;
}
}
printf("Case %d: %d\n",++ff,ans);
}
}
hdu3549 最大流的更多相关文章
- HDU-3549 最大流模板题
1.HDU-3549 Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...
- HDU3549 最大流 裸题
EK算法 时间复杂度o(n*m*m) 因为有反向边每次bfs时间为 n*m 每次删一条边 最多m次 代码 #include<iostream> #include<string.h& ...
- hdu-3549 Flow Problem---最大流模板题(dinic算法模板)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3549 题目大意: 给有向图,求1-n的最大流 解题思路: 直接套模板,注意有重边 传送门:网络流入门 ...
- hdu3549网络流之最大流
Ford-Fulkerson方法:dfs实现 dfs 140ms #include<map> #include<set> #include<cmath> #inc ...
- [hdu3549]Flow Problem(最大流模板题)
解题关键:使用的挑战程序设计竞赛上的模板,第一道网络流题目,效率比较低,且用不习惯的vector来建图. 看到网上其他人说此题有重边,需要注意下,此问题只在邻接矩阵建图时会出问题,邻接表不会存在的,也 ...
- HDU3549:Flow Problem(最大流入门EK)
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <queue> ...
- 网络流(最大流-Dinic算法)
摘自https://www.cnblogs.com/SYCstudio/p/7260613.html 网络流定义 在图论中,网络流(Network flow)是指在一个每条边都有容量(Capacity ...
- 使用C#处理基于比特流的数据
使用C#处理基于比特流的数据 0x00 起因 最近需要处理一些基于比特流的数据,计算机处理数据一般都是以byte(8bit)为单位的,使用BinaryReader读取的数据也是如此,即使读取bool型 ...
- HTML 事件(三) 事件流与事件委托
本篇主要介绍HTML DOM中的事件流和事件委托. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4 ...
随机推荐
- [Day5] Nginx 变量
一. Nginx中的变量原理 提供变量的模块和使用变量的模块 nginx启动,提供变量的模块会在一个回调函数中定义新的变量名和解析出变量的方法. 请求来了以后,使用变量的模块会根据变量名,去调用解析变 ...
- Simple implementation and results of genetic algorithm.
This experiment was done for the final assignment of my Professional English class. This part has be ...
- Browsersync 浏览器自动刷新
Browsersync 是一个很好用的工具,它可以实时监测文件的变动然后自动刷新浏览器,不用每次去点刷新或F5,特别在调试样式时非常有用. browsersync中文网 http://www.bro ...
- input输入框的input事件和change事件
input输入框的onchange事件,要在 input 失去焦点的时候才会触发: 在输入框内容变化的时候不会触发change,当鼠标在其他地方点一下才会触发: onchange 事件也可用于单选框与 ...
- poj 2115 扩展欧几里德
#include<stdio.h> #include<string.h> #define max 32 typedef long long LL; LL pow2[max+]; ...
- javascript go()函数
<a href="javascript:history.go(-1);">返回上一页</a> put this in your input tag < ...
- LintCode_514 Paint Fence
题目 here is a fence with n posts, each post can be painted with one of the k colors.You have to paint ...
- description The request sent by the client was syntactically incorrect.
shi用url传递参数,其他页面都ojbk的 唯独有一个请求 不应该啊 这明显的已经配置好了啊 因为别的请求我也是这样配置的啊,运行是没问题的啊 运行好好的啊 一时间,感觉无从下手了 经过十几分钟各种 ...
- dedecms list标签调用附加表字段--绝对成功
使用list标签调用附加表字段的时候会忽略一个地方,明明附加字段名已经添加进去了就是调用不出来 经过在网上查询了资料,说的天花乱坠,也都实践过一些,但是就是不成功鞋面介绍一下犯的低级错误在哪里 {de ...
- 高可用服务 AHAS 在消息队列 MQ 削峰填谷场景下的应用
在消息队列中,当消费者去消费消息的时候,无论是通过 pull 的方式还是 push 的方式,都可能会出现大批量的消息突刺.如果此时要处理所有消息,很可能会导致系统负载过高,影响稳定性.但其实可能后面几 ...