HDU 1532 Drainage Ditches(最大流)
来源:互联网 发布:旺旺怎么联系淘宝客服 编辑:程序博客网 时间:2024/06/07 07:32
最大流模版题,弄了好多天也没有明白..
今天好不容易根据记忆写了个..
/* xzppp */#include <iostream>#include <vector>#include <cstdio>#include <string.h>#include <algorithm>#include <queue>#include <map>#include <string>#include <cmath>#include <bitset>#include <iomanip>using namespace std;#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define MP make_pair#define PB push_backtypedef long long LL;typedef unsigned long long ULL;typedef pair<int,int > pii;typedef pair<LL,LL> pll;typedef pair<double,double > pdd;typedef pair<double,int > pdi;const int MAXN = 1e5+17;const int MAXM = 1e6+17;const int MAXV = 2*1e3+17;const int BIT = 15+3;const int INF = 0x7fffffff;const LL INFF = 0x3f3f3f3f3f3f3f3f;const int MOD = 998244353;int vis[MAXN];struct edge{ int to,cap,rev; edge(int a,int b,int c):to(a),cap(b),rev(c){};};vector<edge > G[MAXN];void adeg(int from,int to,int cap){ G[from].push_back(edge(to,cap,G[to].size())); G[to].push_back(edge(from,0,G[from].size()-1));}int dfs(int p,int t,int f){ if(p==t) return f; vis[p] = 1; for (int i = 0; i < G[p].size(); ++i) { int next = G[p][i].to; if(!vis[next]&&G[p][i].cap>0) { int d = dfs(next,t,min(G[p][i].cap,f)); if(d>0) { G[p][i].cap -= d; G[next][G[p][i].rev].cap += d; return d; } } } return 0;}int maxflow(int s,int t){ int res = 0; while(1) { memset(vis, 0, sizeof(vis)); int f = dfs(s,t,INF); if(f==0) return res; res += f; }}int main(){ #ifndef ONLINE_JUDGE FFF #endif int m,n; while(cin>>m>>n) { for (int i = 0; i < n; ++i) { G[i].clear(); } for (int i = 0; i < m; ++i) { int u,v,c; scanf("%d%d%d",&u,&v,&c); u--;v--; adeg(u, v, c); } int ans = maxflow(0, n-1); cout<<ans<<endl; } return 0;}
阅读全文
0 0
- HDU 1532 Drainage Ditches (最大网络流)
- HDU 1532 Drainage Ditches (最大网络流)
- hdu 1532 Drainage Ditches(最大网络流)
- hdu 1532 Drainage Ditches 基础最大流
- hdu 1532 Drainage Ditches 最大流
- hdu 1532 Drainage Ditches (最大流)
- [hdu 1532] Drainage Ditches(最大流dinic)
- hdu 1532 Drainage Ditches(最大流)
- hdu 1532 Drainage Ditches 最大流 水题
- hdu 1532 最大网络流 Drainage Ditches
- HDU 1532 Drainage Ditches 最大流
- HDU 1532 Drainage Ditches(最大流)
- Drainage Ditches - HDU 1532 最大流
- HDU 1532--Drainage Ditches【最大流】
- hdu 1532 Drainage Ditches(最大流)
- HDU 1532 Drainage Ditches(最大流)
- hdu 1532 Drainage Ditches【最大流】
- HDU 1532 Drainage Ditches (最大流模板)
- LightOJ
- 排序算法(四)快速排序算法
- Android上Java网络资源访问(二)使用HttpURLConnection多线程下载
- 网络是怎样连接的学习笔记(二)
- java继承初始化随笔
- HDU 1532 Drainage Ditches(最大流)
- book1 unit5 after-class reading 2 : Ready for Danger
- priority_queue用法详解
- javalesuo解析
- kuangbin KMP H题
- 工厂模式(二)-工厂方法模式(C++实现)
- arcpy之计算要素长度及面积
- 0913 Oracle 查询
- 面向对象编程