POJ 1273 最水最水的网络最大流
来源:互联网 发布:辣条属于淘宝哪个类目 编辑:程序博客网 时间:2024/06/18 17:53
直接最大流就可以了。没有任何困难,就是要注意数据范围,每组数据之后清零就可以了。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#include <vector>#define INF 0x7fffffff#define maxn 205#define maxm 300000using namespace std;int vis[maxn],cur[maxn],d[maxn],s,m,n,t;struct Edge{ int from,to,cap,flow;};vector<int>G[maxn];vector<Edge>edges;void init(){ for(int i=1;i<=n;i++)G[i].clear(); edges.clear();}void AddEdge(int from,int to,int cap){ edges.push_back((Edge){from,to,cap,0}); edges.push_back((Edge){to,from,0,0}); int m=edges.size(); G[from].push_back(m-2); G[to].push_back(m-1);}bool BFS(){ memset(vis,0,sizeof vis); queue<int>Q; Q.push(s); d[s]=0; vis[s]=1; while(!Q.empty()) { int x = Q.front();Q.pop(); int len = G[x].size(); for(int i=0;i<len;i++) { Edge &e = edges[G[x][i]]; if(!vis[e.to]&&e.cap>e.flow) { vis[e.to]=1; d[e.to]=d[x]+1; Q.push(e.to); } } } return vis[t];}int DFS(int x ,int a){ if(x==t||a==0)return a; int flow = 0,f; int len = G[x].size(); for(int &i = cur[x];i<len ;i++) { Edge &e = edges[G[x][i]]; if(d[x]+1==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>0) { e.flow+=f; edges[G[x][i]^1].flow-=f; flow+=f; a-=f; if(a==0)break; } } return flow;}int Maxflow(int s ,int t){ int flow=0; while(BFS()) { memset(cur,0,sizeof cur); flow+=DFS(s,INF); } return flow;}int main(){// freopen("in.txt","r",stdin); while(~scanf("%d%d",&m,&n)) { init(); int u,v,w; for(int i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&w); AddEdge(u,v,w); } s=1;t=n; printf("%d\n",Maxflow(s,t)); } return 0;}
0 0
- POJ 1273 最水最水的网络最大流
- poj 1273 网络最大流
- 网络流之最大流 POJ 1273
- POJ 1273 网络流最大流 题解
- poj 1273 Drainage Ditches 网络最大流
- POJ 1273 Drainage Ditches (网络最大流)
- poj 1273 网络最大流(ek)
- 【POJ】1273 Drainage Ditches 网络最大流
- poj 网络最大流模板
- POJ 1273 Drainage Ditches 我的第一道网络流——最大流问题
- POJ 1273 Drainage Ditches(网络流——最大流)
- poj 1273 Drainage Ditches(网络流最大流)
- POJ 1273 Drainage Ditches 网络流最大流
- POJ 1273Drainage Ditches(网络流之最大流)
- POJ 1273 Drainage Ditches(网络流,最大流)
- 【最大流-ISAP】POJ-1273-网络流模板!!
- [笔记] 网络流-最大流 POJ-1273\HDU-4240
- POJ 1273Drainage Ditches --网络流最大流模板题
- UISearchBar 自定义,加背景,取消按钮背景
- 基数排序
- 自己动手写操作系统 第六章 号外:中断处理流程详细分析
- 网络端口的自动翻转(Auto MDI/MDIX)
- HDU 4497 GCD and LCM(拆素数+组合)
- POJ 1273 最水最水的网络最大流
- SQL Server内存遭遇操作系统进程压榨案例
- Merge k Sorted Lists
- 内部排序之插入排序、希尔排序
- 如何将英文pdf装换为中文word
- POJ 2828 treap单点插入,遍历输出。
- 三角形类1
- POJ-3684-Physics Experiment
- UML之类图