HDU3549_Flow Problem(网络流/EK)
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 6987 Accepted Submission(s): 3262
For each test case, the first line contains two integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <= 15, 0 <= M <= 1000)
Next M lines, each line contains three integers X, Y and C, there is an edge from X to Y and the capacity of it is C. (1 <= X, Y <= N, 1 <= C <= 1000)
2
3 2
1 2 1
2 3 1
3 3
1 2 1
2 3 1
1 3 1
Case 1: 1
Case 2: 2
解题报告
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define N 30
#define inf 99999999
using namespace std;
int n,m,a[N],flow,pre[N];
int Edge[N][N];
queue<int >Q;
int bfs()
{
while(!Q.empty())
Q.pop();
memset(a,0,sizeof(a));
memset(pre,0,sizeof(pre));
Q.push(1);
pre[1]=1;
a[1]=inf;
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for(int v=1;v<=n;v++)
{
if(!a[v]&&Edge[u][v]>0)
{
pre[v]=u;
a[v]=min(Edge[u][v],a[u]);
Q.push(v);
}
}
if(a[n])break;
}
if(!a[n])
return -1;
else return a[n];
}
void ek()
{
int a,i;
while((a=bfs())!=-1)
{
for(i=n;i!=1;i=pre[i])
{
Edge[pre[i]][i]-=a;
Edge[i][pre[i]]+=a;
}
flow+=a;
}
}
int main()
{
int t,i,j,u,v,w,k=1;
scanf("%d",&t);
while(t--)
{
flow=0;
memset(Edge,0,sizeof(Edge));
scanf("%d%d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
Edge[u][v]+=w;
}
ek();
printf("Case %d: ",k++);
printf("%d\n",flow);
}
return 0;
}
HDU3549_Flow Problem(网络流/EK)的更多相关文章
- HDU 3549 Flow Problem 网络流(最大流) FF EK
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- HDU 3549 基础网络流EK算法 Flow Problem
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit ...
- 网络流EK
#include <iostream> #include <queue> #include <string.h> #define MAX 302 using nam ...
- HDU1532 Drainage Ditches 网络流EK算法
Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...
- hdu 3549 Flow Problem 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Network flow is a well-known difficult problem f ...
- POJ-3436 ACM Computer Factory(网络流EK)
As you know, all the computers used for ACM contests must be identical, so the participants compete ...
- 网络流Ek算法
例题: Flow Problem HDU - 3549 Edmonds_Karp算法其实是不断找增广路的过程. 但是在找的过程中是找"最近"的一天增广路, 而不是找最高效的一条增 ...
- 【HDU5772】String Problem [网络流]
String Problem Time Limit: 10 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Input Ou ...
- [bzoj3218]a + b Problem 网络流+主席树优化建图
3218: a + b Problem Time Limit: 20 Sec Memory Limit: 40 MBSubmit: 2229 Solved: 836[Submit][Status] ...
随机推荐
- C#Url传递中文参数时解决方法
原文发布时间为:2008-11-05 -- 来源于本人的百度文章 [由搬家工具导入] 1.设置web.config文件。<system.web> <globalization req ...
- 补不manjaro系统
昨天无意间看到:使用不同的主题时,使用midna图标时,关机的按钮和其他的不同,经过摸索,只需要更改替换3个图标即可: (1)进入目录/usr/share/icons/breeze/actions/t ...
- C结构体struct用法小结
结构体和int,float等类型一样是一种常用的类型,它是由各种基本数据类型构成,通常包含有struct关键字,结构体名,结构体成员,结构体变量. 一.结构体定义 通常有3种定义方式,以例子方式表示: ...
- ASP.NET MVC 实现 AJAX 跨域请求
ASP.NET MVC 实现AJAX跨域请求的两种方法 和大家分享下Ajax 跨域的经验,之前也找了好多资料,但是都不行,后来看到个可行的修改了并测试下 果然OK了 希望对大家有所帮助! 通常发送 ...
- AC日记——K-th Number poj 2104
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 52348 Accepted: 17985 Ca ...
- Android判断是否为刘海屏
主要总结主流品牌小米.华为.oppo.vivo的刘海屏判断.在某些特殊页面需要适配刘海屏时,可以用以下方法判断.或者判断屏幕比例是否大于2. /** * 小米刘海屏判断. */ public stat ...
- (5)ASP.NET HTML服务器控件
工具箱 与服务端交互 <body> <form id="form1" runat="server"> <div> <% ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake【暴力/组合数】
A. Far Relative’s Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...
- 浅谈.Net异步编程的前世今生----EAP篇
前言 在上一篇博文中,我们提到了APM模型实现异步编程的模式,通过使用APM模型,可以简化.Net中编写异步程序的方式,但APM模型本身依然存在一些缺点,如无法得知操作进度,不能取消异步操作等. 针对 ...
- java.lang.StackOverflowError at org.eclipse.jetty.util.resource.Resource.<init>(Resource.java:40)
今天做项目的时候,不知道哪根筋搭错了,多写了一句话,导致我忙活了一下午,各种百度,最后在朋友的帮助下,给了我思路,完美解决,不多说,上图. 我的登录页面引入了bootstrap.jsp的东西 解决问题 ...