hdu3549 Flow Problem
来源:互联网 发布:淡斑 知乎 编辑:程序博客网 时间:2024/04/28 07:30
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 7867 Accepted Submission(s): 3661
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最大流开通的第二题,模板只要稍微改动一下就AC了,一遍AC,1——n的最大流问题,这里是t组测试数据,不断的输入即可。注释写的很明白,不再在此赘述。代码如下:#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#define inf 88888888using namespace std;int cap[200][200];int flow[200][200];int a[200];int main(){ int n,m; int i,j; int si,ei,ci; int t; int k=1; while(scanf("%d",&t)!=EOF) //while(scanf("%d %d",&n,&m)!=EOF) { while(t--) { scanf("%d %d",&n,&m); memset(cap,0,sizeof(cap)); for(i=0; i<m; i++) { scanf("%d %d %d",&si,&ei,&ci); cap[si][ei]+=ci; } queue<int>q; memset(flow,0,sizeof(flow)); int f=0; int p[210]; while(1) { memset(a,0,sizeof(a)); a[1]=inf; q.push(1); while(!q.empty())//BFS找增光链 { int u=q.front(); q.pop(); for(int v=1; v<=n; v++) { if(!a[v]&&cap[u][v]>flow[u][v])//找到新节点v { p[v]=u;//记录v的父亲 q.push(v);//并加入队列 a[v] = a[u]<cap[u][v]-flow[u][v]?a[u]:cap[u][v]-flow[u][v]; //a[v]=a[u]<?cap[u][v]-flow[u][v];//s-v路径上的最小残量 } } } if(a[n]==0) break;//找不到,则当前流已经是最大流 for(int u=n; u!=1; u=p[u])//从汇点往回走 { flow[p[u]][u]+=a[n];//更新正向流量 flow[u][p[u]]-=a[n];//更新反向流量 } f+=a[n];//更新从s流出的总流量 } printf("Case %d: %d\n",k++,f);//最后打印总的流量 } } return 0;}
0 0
- hdu3549 Flow Problem (Dinic)
- hdu3549 flow problem
- hdu3549 Flow Problem
- HDU3549-Flow Problem
- HDU3549 Flow Problem
- 【网络流】hdu3549 Flow Problem
- HDU3549 Flow Problem 【最大流】
- HDU3549 Flow Problem(最大流)
- hdu3549 Flow Problem【最大流】
- hdu3549 Flow Problem 最大流模板 isap
- hdu3549--Flow Problem(初识最大流)
- HDU3549 Flow Problem【最大流】【Edmond-Karp】
- hdu3549 Flow Problem(最大流)
- 网络流入门题hdu3549(Flow Problem)
- hdu3549 Flow Problem--EK算法 & 最大流
- hdu3549 Flow Problem(EKarp||Dinic)
- HDU3549 Flow Problem(ford-fulkerson算法)
- hdu3549-Flow Problem(最大流&EK)
- HDU 3549 Flow Problem
- hdoj 1022 Train Problem I(用栈解决法)
- Linux mint 下安装Fcitx中文输入法
- POJ3249 Test for Job 【DAG】+【记忆化搜索】
- 图片加水印工具类
- hdu3549 Flow Problem
- 秒杀多线程第十篇 生产者消费者问题
- 用WebCollector做Web挖掘(实例1)
- google 2015最新的校招测试题与思路
- TCP协议状态图
- ant debug最常见的一个错误解决
- 【备忘录】僵尸进程与孤儿进程以及一些进程间的知识
- 算法导论学习_数论
- HDU-1465-不容易系列之一(简单全错位排序)