标签:思路 while lld clu int std org ems print
/** 题目:poj1273 Drainage Ditches 链接:http://poj.org/problem?id=1273 题意:裸的最大流 思路:裸的最大流 */ #include<iostream> #include<cstring> #include<vector> #include<cstdio> #include<algorithm> using namespace std; const int INF = 0x3f3f3f3f; typedef long long LL; const int N = 250; struct edge{ int to, cap, rev; }; vector<edge> G[N]; bool used[N]; void add_edge(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 v,int t,int f) { if(v==t) return f; used[v] = true; for(int i = 0; i < G[v].size(); i++){ edge&e = G[v][i]; if(!used[e.to]&&e.cap>0){ int d = dfs(e.to,t,min(f,e.cap)); if(d>0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } LL max_flow(int s,int t) { LL flow = 0; for(;;){ memset(used, 0, sizeof used); int f = dfs(s,t,INF); if(f==0) return flow; flow+=f; } } int main() { int n , m; while(scanf("%d%d",&m,&n)==2) { int u, v, cap; for(int i = 0; i <= n; i++) G[i].clear(); for(int i = 0; i < m; i++){ scanf("%d%d%d",&u,&v,&cap); add_edge(u,v,cap); } printf("%lld\n",max_flow(1,n)); } return 0; }
标签:思路 while lld clu int std org ems print
原文地址:http://www.cnblogs.com/xiaochaoqun/p/7181944.html