hdu3549—Flow Problem(FF模板)
来源:互联网 发布:thinkphp sql注入漏洞 编辑:程序博客网 时间:2024/05/29 03:32
题目链接:传送门
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 16525 Accepted Submission(s): 7792
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)
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
23 21 2 12 3 13 31 2 12 3 11 3 1
Sample Output
Case 1: 1Case 2: 2
FF算法模板
#include <cstdio>#include <algorithm>using namespace std;#define size1 20#define size2 1009int N,M;//边的结构struct edge_t{ int node; int c;//c为容量 edge_t* next; edge_t* redge;//指向反向边}Edge[size2*2];int ECnt;//图的邻接表edge_t* Ver[size1];void init(){ ECnt = 0; fill(Ver,Ver+size1,(edge_t*)0);}//生成双向边void mkEdge(int a,int b,int c){ int t1 = ECnt++; int t2 = ECnt++; Edge[t1].node = b; Edge[t1].c = c; Edge[t1].next = Ver[a]; Edge[t1].redge = Edge + t2; Ver[a] = Edge + t1; Edge[t2].node = a; Edge[t2].c = 0; Edge[t2].next = Ver[b]; Edge[t2].redge = Edge + t1; Ver[b] = Edge + t2;}bool F[size1];//u当前节点,f为当前流//寻找增广路径int dfs(int u,int f){ if ( u == N ) return f; F[u] = true; for(edge_t*p=Ver[u];p;p=p->next){ int v = p->node; if( F[v] ) continue; int c = p->c; if ( c > 0 ){ int t = dfs(v,min(c,f)); if ( 0 == t ) continue; p->c -= t; p->redge->c += t; return t; } } return 0;}int solve(){ int ret = 0; while(1){ fill(F,F+size1,false); int t = dfs(1,INT_MAX); if ( 0 == t ) return ret; ret += t; }}void read(){ scanf("%d%d",&N,&M); init(); for(int i=0;i<M;++i){ int a,b,c; scanf("%d%d%d",&a,&b,&c); mkEdge(a,b,c); }}int main(){ int Count = 0; int T; scanf("%d",&T); while( T-- ) { read(); printf("Case %d: %d\n",++Count,solve()); } return 0;}
阅读全文
0 0
- hdu3549—Flow Problem(FF模板)
- hdu3549 Flow Problem 最大流模板 isap
- hdu3549 Flow Problem(最大流)
- hdu3549 Flow Problem(EKarp||Dinic)
- hdu3549-Flow Problem(最大流&EK)
- Hdu3549 Flow Problem(isap+bfs优化)
- hdu3549 Flow Problem (Dinic)
- hdu3549 flow problem
- hdu3549 Flow Problem
- HDU3549-Flow Problem
- HDU3549 Flow Problem
- HDU3549 - Flow Problem(模板网络流 + Ford-Fulkerson算法)
- HDU3549 Flow Problem 【网络流E-K算法模板】
- 【网络流】hdu3549 Flow Problem
- HDU3549 Flow Problem 【最大流】
- HDU3549 Flow Problem(最大流)
- hdu3549 Flow Problem【最大流】
- HDU3549 Flow Problem (网络流入门题)
- 嵌入式系统烧写
- C++函数模板(泛型编程一)
- Linux 集群管理工具Clustershell,pssh
- java-多态(概念、扩展、转型、示例、多态中成员的特点、)
- javaweb
- hdu3549—Flow Problem(FF模板)
- Streaming kakfa 扩展源码 指定起始offset和结束offset
- 一个支持高并发的jdbc,内置连接池
- Spark成长之路(6)-Correlation
- 查看 SELinux状态及关闭SELinux
- angular使用下拉框+表单
- Java基础之final关键字
- 获取 Windows 系统版本号
- mac 下的开发工具