HDU3549 Flow Problem(ford-fulkerson算法)
来源:互联网 发布:淘宝腾讯会员 编辑:程序博客网 时间:2024/06/10 02:35
Flow ProblemTime Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 13984 Accepted Submission(s): 6683Problem DescriptionNetwork flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.InputThe first line of input contains an integer T, denoting the number of test cases.For each test case, the first line contains two integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <= 15, 0 <= M <= 1000)Next M lines, each line contains three integers X, Y and C, there is an edge from X to Y and the capacity of it is C. (1 <= X, Y <= N, 1 <= C <= 1000)OutputFor each test cases, you should output the maximum flow from source 1 to sink N.Sample Input23 21 2 12 3 13 31 2 12 3 11 3 1Sample OutputCase 1: 1Case 2: 2AuthorHyperHexagon
第一次接触,最大流问题,其实暑假训练的时候有提及过,之前比赛也接触过费用流的题目,不过不会做。先基础入门。12月1号,生命里最美好的一天,定个小目标,加油。最大流,直接ford-fulkerson,记得c清空vector,然后就可以了。
#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<cctype>#include<cmath>#include<ctime>#include<string>#include<stack>#include<deque>#include<queue>#include<list>#include<set>#include<map>#include<cstdio>#include<limits.h>#define MOD 1000000007#define fir first#define sec second#define fin freopen("/home/ostreambaba/文档/input.txt", "r", stdin)#define fout freopen("/home/ostreambaba/文档/output.txt", "w", stdout)#define mes(x, m) memset(x, m, sizeof(x))#define Pii pair<int, int>#define Pll pair<ll, ll>#define INF 1e9+7#define inf 0x3f3f3f3f#define Pi 4.0*atan(1.0)#define lowbit(x) (x&(-x))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long ll;typedef unsigned long long ull;const double eps = 1e-12;const int maxn = 16;using namespace std;inline int read(){ int x(0),f(1); char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}struct edge{ int to,cap,rev;};vector<edge> G[maxn];bool used[maxn],f;void addEdge(int from,int to,int cap){ G[from].push_back({to,cap,G[to].size()}); G[to].push_back({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;}int maxFlow(int s,int t){ int flow=0; for(;;){ mes(used,false); int f=dfs(s,t,INF); if(0==f){ return flow; } flow+=f; }}int main(){ // fin; int t,n,m,a,b,c; int cnt=0; t=read(); while(t--){ cout<<"Case "<<++cnt<<": "; for(int i=0;i<=n;++i){ G[i].clear(); } n=read(),m=read(); while(m--){ a=read(),b=read(),c=read(); addEdge(a,b,c); } cout<<maxFlow(1,n)<<endl; } return 0;}
0 0
- HDU3549 Flow Problem(ford-fulkerson算法)
- HDU3549 - Flow Problem(模板网络流 + Ford-Fulkerson算法)
- HDU 3549 Flow Problem (Ford-Fulkerson&Dinic)
- HDU 3549 Flow Problem【最大流入门题】【Ford-Fulkerson算法】【Dinic算法】【ISAP算法】
- hdu 3549 Flow Problem 最大流模板题 Ford-Fulkerson算法
- HDU 3549 Flow Problem(网络流入门题-最大流的Ford-Fulkerson算法)
- hdu3549 Flow Problem--EK算法 & 最大流
- 【资料】Ford-Fulkerson Algorithm for Maximum Flow Problem
- Ford-Fulkerson algorithm to solve the max flow problem
- hdu3549 Flow Problem (Dinic)
- hdu3549 flow problem
- hdu3549 Flow Problem
- HDU3549-Flow Problem
- HDU3549 Flow Problem
- HDU3549最大流多路增广(Ford-Fulkerson邻接矩阵)
- hdu3549(最大流ford-fulkerson模板)
- hdu3549(网络流入门题-最大流的Ford-Fulkerson算法)
- hdu3549 Flow Problem(dinic算法和ISAP算法)
- 1015. Reversible Primes (20)/YHF/2016.12.1
- WebStorm下配置supervisor热部署NodeJS
- CMakeList配置之编译多个.cpp文件
- Java 多线程 并发编程
- 自定义view绘制时钟
- HDU3549 Flow Problem(ford-fulkerson算法)
- redis基础知识
- JSP中九大内置对象与四大作用域
- 计算字符串中字符的相连字符的最大长度
- doxygen和graphviz来产生源代码函数调用图
- SSH三大框架JAR包官方下载地址
- poj 2255 Tree Recovery 递归
- ds 1.1 单身狗的进化
- 非窗口实现定时器的方法