POJ 1273 Drainage Ditches 网络流基础题
来源:互联网 发布:安卓时间校准软件 编辑:程序博客网 时间:2024/05/29 17:29
题目扫了一眼,直接EK求解,1A。
#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cmath>#include <cstring>#include <queue>#include <set>#include <vector>#include <stack>#include <map>#include <iomanip>#define PI acos(-1.0)#define Max 205#define inf 1<<28#define LL(x) (x<<1)#define RR(x)(x<<1|1)using namespace std;int Map[Max][Max];int flow[Max];int start,end;int q[Max*100];int path[Max];int bfs(){ flow[1]=inf; int num=0,cnt=0; q[num++]=1; memset(path,-1,sizeof(path)); path[1]=1; int n=end; while(num>cnt) { int temp=q[cnt++]; if(temp==end)break; for(int i=1;i<=n;i++) { if(path[i]==-1&&Map[temp][i]) { flow[i]=min(flow[temp],Map[temp][i]); q[num++]=i; path[i]=temp; } } } if(path[end]==-1)return -1; return flow[end];}long long Edmonds_Karp(){ int now,step,pre; long long max_flow=0; while((step=bfs())!=-1) { now=end; max_flow+=step; while(now!=start) { pre=path[now]; Map[pre][now]-=step; Map[now][pre]+=step; now=pre; } } return max_flow;}int main(){ int i,j,k,l,n,m,a,b; while(scanf("%d%d",&m,&n)!=EOF) { memset(Map,0,sizeof(Map)); while(m--) { scanf("%d%d%d",&a,&b,&l); Map[a][b]+=l; } start=1,end=n; printf("%lld\n",Edmonds_Karp()); } return 0;}
- POJ 1273 Drainage Ditches 网络流基础
- POJ 1273 Drainage Ditches 网络流基础题
- poj 1273 Drainage Ditches 网络最大流
- poj 1273 Drainage Ditches--网络流
- 【网络流】poj 1273 Drainage Ditches
- 网络流poj(1273)Drainage Ditches
- POJ 1273 Drainage Ditches 【网络流】
- POJ 1273 Drainage Ditches 网络流模版
- POJ 1273 Drainage Ditches (网络最大流)
- POJ 1273 - Drainage Ditches (网络流)
- 【网络流】 POJ 1273 Drainage Ditches
- 网络流模板 POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches 经典网络流
- POJ 1273 Drainage Ditches 网络流算法 .
- POJ 1273 Drainage Ditches (网络流)
- 【POJ】1273 Drainage Ditches 网络最大流
- POJ 1273 Drainage Ditches 网络流 ISAP
- POJ 1273Drainage Ditches --网络流最大流模板题
- CF#134
- Exadata 的 Flash Cache的威力
- HDU 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】
- 正确结束Java Thread的方法
- unix shell 编程(读书笔记3):提高篇
- POJ 1273 Drainage Ditches 网络流基础题
- 好非主流的内存池用法,参考了某大牛的写法改造了一下。
- 隐含的排序问题 质量相同石头木头配对问题
- 不同于2010年春晚的《传奇》——如此温暖
- SVN服务端自动同步工具发布
- 由.Net类库提供的农历计算(C#农历)
- VS2008中MFC中集成对话框工程遇到控件ID变化成4位数字
- 关于接口描述符中bAlternateSetting的使用
- android 编译 英文说明文档