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] ...
随机推荐
- BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 700 Solved: ...
- 一个简单有效的兼容IE7浏览器的办法
最近发现了一个简单有效的兼容IE7浏览器的办法 直接将下面代码复制道页面 <meta http-equiv="X-UA-Compatible" content="I ...
- c语言中的main函数讨论
**从刚开始写C程序,相比大家便开始写main()了.虽然无数的教科书和老师告诉我们main是程序的入口.那么main函数是怎么被调用的,怎么传入参数,返回的内容到哪里了,返回的内容是什么?接下来我们 ...
- C# 时间戳和普通时间相互转换
// 时间戳转为C#格式时间 private DateTime StampToDateTime(string timeStamp) { DateTime dateTimeStart = TimeZon ...
- UVALive 3517:Feel Good(单调栈 Grade C)
VJ题目链接 题意: n个数,求区间[l,r] 使得 sum[l,r]*min(a[l],a[l+1],...,a[r]) 最大.若有多种答案,输出区间最短的.若还有多组,输出最先出现的. 思路: 求 ...
- asp.net mvc 自定义模型绑定
在asp.net mvc的控制器中如果能够活用模型的自动绑定功能的话能够减少许多工作量.但是如果我们想要对前台传来的数据进行一些处理再绑定到模型上,该怎么做呢? 这里用一个绑定用户数据的小案例来讲解a ...
- Auto-Test 要点纪录(一)
1,select下拉框类型 使用工具可以看到html对应标签为<select>这类标签才是真正的下拉框类型就需要对应的方法,不能但看页面上的效果,有的做成了效果但其实不是select类型即 ...
- ScutSDK 0.9版本发布
ScutSDK简介: ScutSDK是和Scut游戏服务器引擎,简化客户端开发的配套SDK,她彻底打通了Scut开源游戏服务器引擎与客户端引擎(如Cocos2d-x/Quick-x/Unity3D)项 ...
- REMOTE HOST IDENTIFICATION HAS CHANGED 问题解决
今天处理 ssh连接至 ubuntu 服务器时,提示以下错误: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING ...
- su、sudo、sudo su、sudo -i的用法和区别
sudo : 暂时切换到超级用户模式以执行超级用户权限,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码.不过有时间限制,Ubuntu默认为一次时长15分钟.su : 切换到某某用户模式,提 ...