Flow Problem

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

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
 
代码:
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
int mat[][];
int dist[];
int n,m;
int min(int a,int b)
{
return a<b?a:b;
}
bool bfs(int st,int to){
memset(dist,-,sizeof(dist));
queue<int>q;
q.push(st);
dist[st]=;
int t;
while(!q.empty()){
t=q.front();
q.pop();
for(int i=;i<=n;i++){
if(dist[i]<&&mat[t][i]>){
dist[i]=dist[t]+;
if(i==to)return ;
q.push(i);
}
}
}
return ;
}
int dfs(int st,int to,int flow)
{
int tem;
if(st==to||flow==) return flow;
for(int i=;i<=n;i++){
if((dist[i]==dist[st]+)&&mat[st][i]>&&(tem=dfs(i,to,min(mat[st][i],flow))))
{
mat[st][i]-=tem;
mat[i][st]+=tem;
return tem;
}
}
return ;
}
int Dinic(int st,int en)
{
int ans=;
while(bfs(st,en))
ans+=dfs(st,en,inf);
return ans;
}
int main(){
int cas,i,a,b,c;
scanf("%d",&cas);
for(i=;i<=cas;i++){
scanf("%d%d",&n,&m);
memset(mat,,sizeof(mat));
while(m--){
scanf("%d%d%d",&a,&b,&c);
mat[a][b]+=c;
}
printf("Case %d: %d\n",i,Dinic(,n));
}
return ;
}

hdu------(3549)Flow Problem(最大流(水体))的更多相关文章

  1. hdu - 3549 Flow Problem (最大流模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...

  2. hdu 3549 Flow Problem (最大流)

    裸最大流,做模板用 m条边,n个点,求最大流 #include <iostream> #include <cstdio> #include <cstring> #i ...

  3. hdu 3549 Flow Problem 最大流 Dinic

    题目链接 题意 裸的最大流. 学习参考 http://www.cnblogs.com/SYCstudio/p/7260613.html Code #include <bits/stdc++.h& ...

  4. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  5. 网络流 HDU 3549 Flow Problem

    网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...

  6. hdu 3549 Flow Problem【最大流增广路入门模板题】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others ...

  7. hdu 3549 Flow Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Description Network flow is a well- ...

  8. HDU 3549 Flow Problem (最大流ISAP)

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  9. hdu 3549 Flow Problem Edmonds_Karp算法求解最大流

    Flow Problem 题意:N个顶点M条边,(2 <= N <= 15, 0 <= M <= 1000)问从1到N的最大流量为多少? 分析:直接使用Edmonds_Karp ...

  10. HDU 3549 Flow Problem 网络流(最大流) FF EK

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

随机推荐

  1. 。JavaSE------初识Java

    我的老师告诉我,命运眷顾有志者,天道酬勤. 有时在梦里幻想的再多终究也只是梦, 不如脚踏实地一步步往前走来的踏实. ------------------------------------------ ...

  2. UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类

    转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...

  3. JSONObject.fromObject

    JSONObject.fromObjectjava.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRun ...

  4. [C和指针]第五部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. poj 2954 Triangle(Pick定理)

    链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  6. vim功能使用

    转自:http://blog.csdn.net/xiajun07061225/article/details/7039413 vi与vim vi编辑器是所有Unix及Linux系统下标准的编辑器,他就 ...

  7. 使用Invoke、委托函数

    //Invoke(new MethodInvoker(delegate() //{ // DataBind(); //}));

  8. LINQ之路 2:C# 3.0的语言功能(上)

    在上一篇的LINQ介绍中,我们已经看到了隐式类型变量var,扩展方法(extension method)和lambda表达式的身影.没错,他们正是LINQ技术的基石,是他们让LINQ的实现成为可能,并 ...

  9. 无法在web服务器上启动调试。打开的URL的IIS辅助进程当前没有运行。

    调试时弹出:无法在web服务器上启动调试.打开的URL的IIS辅助进程当前没有运行.

  10. iOS - UIAlertView

    前言 NS_CLASS_DEPRECATED_IOS(2_0, 9_0, "UIAlertView is deprecated. Use UIAlertController with a p ...