hdu 3549 Flow Problem【Dinic最大流】
来源:互联网 发布:淘宝怎么注册企业账号 编辑:程序博客网 时间:2024/06/08 06:51
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 12954 Accepted Submission(s): 6175
Problem Description
Network 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.
Input
The 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)
Output
For each test cases, you should output the maximum flow from source 1 to sink N.
Sample Input
2
3 2
1 2 1
2 3 1
3 3
1 2 1
2 3 1
1 3 1
Sample Output
Case 1: 1
Case 2: 2
Author
HyperHexagon
Source
HyperHexagon's Summer Gift (Original tasks)
题目大意:
t组数据,n个点,m条边,求最大流。
记录属于自己的模板!
Dinic 358ms
Ford_Fulkerson 1808ms
#include<stdio.h>#include<string.h>#include<queue>using namespace std;#define INF 0x3f3f3f3fint head[100000];struct edge{ int from,to,w,next;}e[1000000];int div[100000];int n,m,cont,ss,tt;void add(int from,int to,int w){ e[cont].to=to; e[cont].w=w; e[cont].next=head[from]; head[from]=cont++;}int makediv(){ memset(div,0,sizeof(div)); queue<int >s; s.push(ss); div[ss]=1; while(!s.empty()) { int u=s.front(); if(u==tt)return 1; s.pop(); for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; int w=e[i].w; if(w&&div[v]==0) { div[v]=div[u]+1; s.push(v); } } } return 0;}int Dfs(int u,int maxflow,int tt){ if(u==tt)return maxflow; int ret=0; for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; int w=e[i].w; if(w&&div[v]==div[u]+1) { int f=Dfs(v,min(maxflow-ret,w),tt); e[i].w-=f; e[i^1].w+=f; ret+=f; if(ret==maxflow)return ret; } } return ret;}void Dinic(){ ss=1;tt=n; int ans=0; while(makediv()==1) { ans+=Dfs(ss,INF,tt); } printf("%d\n",ans);}int main(){ int t; int kase=0; scanf("%d",&t); while(t--) { cont=0; memset(head,-1,sizeof(head)); scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { int x,y,w; scanf("%d%d%d",&x,&y,&w); add(x,y,w); add(y,x,0); } printf("Case %d: ",++kase); Dinic(); }}
- HDU 3549--Flow Problem 【最大流 && dinic】
- hdu 3549 Flow Problem【Dinic最大流】
- hdu 3549 Flow Problem (最大流—EK—Dinic)
- [HDU] 3549 Flow Problem [最大流][Dinic][读取优化]
- HDU 3549 Flow Problem 最大流 最小增广路 DINIC算法 也是46MS
- hdu 3549 Flow Problem (第二篇) Dinic算法 最大流问题
- HDU 3549 Flow Problem(最大流+EK邻接表||邻接矩阵||dinic算法模板比较)
- Flow Problem 【最大流 dinic】模版
- 【网络流】HDU 1532 Drainage Ditches(最大流Ford-Fulkersson)+HDU 3549 Flow Problem(最大流Dinic算法)
- hdu 3549 Flow Problem(简单网络流Dinic)
- HDU 3549 Flow Problem (Ford-Fulkerson&Dinic)
- HDU-3549 Flow Problem【最大流】
- hdu 3549 Flow Problem【最大流】
- hdu 3549 Flow Problem 最大流
- hdu 3549 Flow Problem (最大流)
- hdu - 3549 - Flow Problem(最大流)
- Hdu 3549 Flow Problem - 最大流
- HDU 3549 Flow Problem 最大网络流
- Vue.js计算属性
- TTL电平、CMOS电平、RS232电平的区别
- Examining the Rooms hdu 3625
- solr配置文件schema文件中字段的介绍
- Qualcomm平台camera调试移植入门
- hdu 3549 Flow Problem【Dinic最大流】
- 51nod1486 大大走格子
- Java线程安全与不安全
- phpexcel
- poj 2253 Frogger
- 372. Super Pow
- STL源码剖析(四)---空间配置器
- 省市县三级联动
- 样式化复选框(Styling checkbox) & 扩展实现“开关按钮效果”