poj 1273
来源:互联网 发布:mumu安卓模拟器mac版 编辑:程序博客网 时间:2024/05/14 10:02
题目传送门:这里
裸的最大流,复习了下EK算法,好吧,掌握的还是最慢的算法。。。。。EK比较好明白。。。。。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#define inf 1<<29using namespace std;int m,n,a,b,c;int p[205][205];int pre[205];bool v[205];bool bfs(int s,int t)//搜索增广路径{ memset(v,0,sizeof(v)); int r; queue<int>q; q.push(s); v[s]=1; while(!q.empty()) { r=q.front(); q.pop(); for(int i=1;i<=m;i++) { if(p[r][i]>0&&v[i]==0) { pre[i]=r; if(i==t)return true; q.push(i); v[i]=1; } } } return false;}int ek(int s,int t){ int f=0; int mf; while(bfs(s,t)) { mf=inf; for(int i=t;i!=s;i=pre[i])mf=p[pre[i]][i]<mf?p[pre[i]][i]:mf;//找到增广路径上的残留网络最小的一段 for(int i=t;i!=s;i=pre[i]) { p[pre[i]][i]-=mf; p[i][pre[i]]+=mf; } f+=mf; } return f;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { memset(p,0,sizeof(p)); for(int i=0;i<n;i++) { scanf("%d%d%d",&a,&b,&c); p[a][b]+=c; } cout<<ek(1,m)<<endl; } return 0;}
- POJ 1273
- poj 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273
- POJ-1273
- poj-1273
- poj 1273
- poj 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- Linux内核分析 - 网络[十六]:TCP三次握手
- 黑马程序员—SQL系列 (四)
- HTTP基本认证(HTTP Basic Athorization)过程分析
- java实训第四次课后笔记—函数
- Android 高级绘图
- poj 1273
- 配置CyanogenMod 10编译环境
- POJ 2942: Knights of the Round Table
- 题目1201:二叉排序树
- mysql命令行修改字符编码
- Toshiba L700 拆机记录
- php实现server(demo)
- Java学习疑点(5)--使用多线程的时候如何注意避免死锁发生?
- 的撒大声地