hdu 1532 Drainage Ditches(EK算法)
2016-03-17 20:04
423 查看
输入m n, m是边数,n是点数。
接下来m行: 起点,终点,最大流量。
求以 1 为源点, n为汇点的最大流。
裸的最大流算法
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <list> #include <queue> #include <map> using namespace std; #define INF 0x3f3f3f3f int flow[220][220]; int vis[220],pre[220]; int n,m; int max_flow() { int ans = 0; while(1) { memset(vis,0,sizeof(vis)); memset(pre,0,sizeof(pre)); queue<int> Q; vis[1] = 1; Q.push(1); while(!Q.empty()) { int cnt = Q.front(); Q.pop(); if(cnt == n) break; for(int i = 1; i <= n; i++) if(!vis[i] && flow[cnt][i] > 0) { vis[i] = 1; pre[i] = cnt; Q.push(i); } } if(!vis ) break; int Max = INF; for(int i = n; i != 1; i = pre[i]) Max = min(Max,flow[pre[i]][i]); for(int i = n; i != 1; i = pre[i]) { flow[pre[i]][i] -= Max; flow[i][pre[i]] += Max; } ans += Max; } return ans; } int main() { int t,C = 1; //scanf("%d",&t); while(scanf("%d%d",&m,&n) != EOF) { memset(flow,0,sizeof(flow)); for(int i = 0; i < m; i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); flow[u][v] += w; } printf("%d\n",max_flow()); } }
相关文章推荐
- Kafka设计解析(二):Kafka High Availability (上)
- Migrate a Domain-based Namespace to Windows Server 2008 Mode
- could not bind to address 0.0.0.0:443 no listening sockets available, shutting d
- ADB server didn't ACK failed to start daemon 完美解决汇总
- 同一台服务器运行多套kamailio服务
- Xenomai补丁的安装
- 启动 angular-phonecat 项目时出现这玩意 。('The header content contains invalid characters');
- scala中的Trait
- AI-伪AI 人工智能 alphago
- 使用traits
- Canvas和Paint的那点事(1)
- 《ALPHAGO vs 李世石》- 人工智能攻下人类最后的堡垒?
- No valid signing identities (i.e. certificate and private key pair) matching the team ID “(null)” were found.
- Jenkins——应用篇——插件使用——Mailer Plugin
- 本地客户端远程调用Service(AIDL)找不到该Service
- ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
- UVa10976 - Fractions Again?!
- Aizu - 0033(深搜)
- 【案例】RAID卡写策略改变引发的问题
- Pairs Forming LCM(素因子分解+lcm)