Flow Problem

Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 10184    Accepted Submission(s): 4798

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
 
Recommend
zhengfeng   |   We have carefully selected several similar problems for you:  1532 3572 3416 3081 3491 

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int dp[][],pre[];
const int tmin=;
int maxflow;
void EK(int start,int end,int n){
while(){
queue<int>q;
q.push();
int minflow=tmin;
memset(pre,,sizeof(pre));
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<=n;i++){
if(dp[u][i]>&&!pre[i]){
pre[i]=u;
q.push(i);
}
}
}
if(pre[end]==)
break;
for(int i=end;i!=start;i=pre[i]){
minflow=min(dp[pre[i]][i],minflow);
}
for(int i=end;i!=start;i=pre[i]){
dp[pre[i]][i]-=minflow;
dp[i][pre[i]]+=minflow;
}
maxflow+=minflow;
}
}
int main(){
int count=;
int n,m;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
memset(dp,,sizeof(dp));
memset(pre,,sizeof(pre));
count++;
int u,v,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
dp[u][v]+=w;
}
maxflow=;
EK(,n,n);
printf("Case %d: %d\n",count,maxflow);
}
return ;
}

最新文章

  1. 从CIO、CEO、CFO、COO...到CVO 这22个你了解几个? (史上最完整版)
  2. yii框架中保存第三方登录信息
  3. Pictures of Ascii Art
  4. VS调试错误:“没有可用于当前位置的源代码”的解决方案
  5. windows phone 之手势识别(Manipulation)
  6. unity读取Sqlite数据库
  7. CodeForces 22C System Administrator
  8. HTTPS的学习总结
  9. VC学习笔记: 1. Window程序内部运行机制
  10. 前台ajax加载数据
  11. 微信小程序登陆授权
  12. JDK1.8源码(二)——java.lang.Integer 类
  13. 接口测试(jmeter和postman 接口使用)
  14. Java虚拟机知识汇总
  15. kali linux 安装wps office
  16. 【Beta阶段】M2事后分析
  17. linux下mysql 8.0安装
  18. _itemmod_creation_enchant
  19. java的异常抛出和String类常用方法
  20. 使用Gnupg对Linux系统中的文件进行加密

热门文章

  1. 散度(Divergence)和旋度(Curl)
  2. 第32章 TIM—高级定时器—零死角玩转STM32-F429系列
  3. 关于vue中的nextTick深入理解
  4. Large-scale Scene Understanding (LSUN)
  5. 关于webpack打包vue后vendor包过大的问题
  6. C# CheckBoxList 实现全选/反选功能怎么写?
  7. C#把日期转化成星期
  8. CMD批处理复制目录下所有文件
  9. 简单了解一下oracle中的显示游标和存储过程
  10. 手机连上同一个局域网的PC,修改项目的vhost配置