HDU 3549(网络流入门之最大流)
来源:互联网 发布:软件系统用户手册 编辑:程序博客网 时间:2024/05/29 08:35
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 10327 Accepted Submission(s): 4866
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
Author
HyperHexagon
Source
HyperHexagon's Summer Gift (Original tasks)
n个点m条边,找到1到n使得流量最大。
解题思路;找出所有的增广路径,然后再找增广路径上的边,找出最小的流量!!
#include <cstdio>#include <cmath>#include <queue>#include <iostream>#include <algorithm>#include <cstring>using namespace std;int n,m;int map1[1001][1001];int pre[1001];int vis[1001];int s,t;bool BFS(){ int i,cur; queue<int>q; memset(pre,0,sizeof(pre)); memset(vis,0,sizeof(vis)); vis[s]=1; q.push(s); while(!q.empty()) { cur=q.front(); q.pop(); if(cur==t) return 1; for(i=1; i<=n; i++) { if(!vis[i] &&map1[cur][i]) { q.push(i); pre[i]=cur; vis[i]=1; } } } return 0;}//找增广路径int Max_flow(){ int i,ans=0; while(1) { if(!BFS()) return ans; int Min=0x7f7f7f7f; for(i=t; i!=s; i=pre[i]) Min=min(Min,map1[pre[i]][i]); for(i=t; i!=s; i=pre[i]) { map1[pre[i]][i]-=Min; map1[i][pre[i]]+=Min; } ans+=Min; }}//找增广路径上的最小流量int main(){ int T; cin>>T; int v,u,c; int k=1; while(T--) { scanf("%d%d",&n,&m); memset(map1,0,sizeof(map1)); s=1,t=n; while(m--) { scanf("%d%d%d",&u,&v,&c); map1[u][v]+=c; } printf("Case %d: %d\n",k++,Max_flow()); } return 0;}
0 0
- HDU 3549(网络流入门之最大流)
- HDU 3549 Flow Problem(网络流入门题-最大流的Ford-Fulkerson算法)
- hdu 3549 最大流入门
- NYOJ 323 && HDU 1532 && POJ 1273 Drainage Ditches (网络流之最大流入门)
- poj 1273 Drainage Ditches(网络流入门之最大流)
- 网络流最大流入门(洛谷P3376)
- HDU 3549 Flow Problem(最大流入门)
- hdu 3549 最大流入门题
- HDU 3549 Flow Problem(最大流入门)
- 最大流入门 poj 1273 && hdu 3549
- HDU 3549 Flow Problem(最大流入门)
- HDU 3549 Flow Problem 网络流入门
- 网络流——最大流入门题目 HDU 1532——Drainage Ditches
- 网络流入门—用于最大流的Dinic算法
- 图论 - 网络流_最大流入门题
- 网络流入门—用于最大流的Dinic算法
- [网络流入门,简单题]poj1273Drainage Ditches最大流
- 网络流入门—用于最大流的Dinic算法
- scala的REPL shell的调用
- 在gentoo中打开tomcat的远程调试开关
- poj(2184)——Cow Exhibition(01背包变形)
- Mac OS xCode5.1 配置 Cocos2d-x 3.0 开发环境
- 基于奇异值分解的图像压缩与除噪
- HDU 3549(网络流入门之最大流)
- linux进程间的通信--共享内存
- java命令行提示:找不到或无法加载主类
- 深入分析ClassLoader
- Qt 判断一个IP地址是否有效
- 初时MVC
- IOS开发初学--XCODE篇
- Android基础知识之四大组件Activity(四)保存Activity的状态
- STM32串口程序(寄存器版)