题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549

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.
题意:不能再简单了这题意,很裸的告诉你根据输入来求解最大流。
解法:网络流算法求解最大流,模板题,Dinic。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#define inf 0x7fffffff
using namespace std;
const int maxn=; int n,m;
int graph[maxn][maxn],d[maxn]; int bfs()
{
memset(d,,sizeof(d));
d[]=;
queue<int> Q;
Q.push();
while (!Q.empty())
{
int u=Q.front() ;Q.pop() ;
for (int v= ;v<=n ;v++)
{
if (!d[v] && graph[u][v]>)
{
d[v]=d[u]+;
Q.push(v);
if (v==n) return ;
}
}
}
return ;
} int dfs(int u,int flow)
{
if (u==n || flow==) return flow;
int cap=flow;
for (int v= ;v<=n ;v++)
{
if (d[v]==d[u]+ && graph[u][v]>)
{
int x=dfs(v,min(cap,graph[u][v]));
cap -= x;
graph[u][v] -= x;
graph[v][u] += x;
if (cap==) return flow;
}
}
return flow-cap;
} int Dinic()
{
int sum=;
while (bfs()) sum += dfs(,inf);
return sum;
} int main()
{
int t,ncase=;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
int a,b,c;
memset(graph,,sizeof(graph));
for (int i= ;i<m ;i++)
{
scanf("%d%d%d",&a,&b,&c);
graph[a][b] += c;
}
printf("Case %d: %d\n",ncase++,Dinic());
}
return ;
}

hdu 3549 Flow Problem 网络流的更多相关文章

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

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

  2. 网络流 HDU 3549 Flow Problem

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

  3. HDU 3549 Flow Problem(最大流)

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

  4. hdu 3549 Flow Problem

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

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

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

  6. HDU 3549 Flow Problem(最大流模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include< ...

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

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

  8. hdu 3549 Flow Problem (网络最大流)

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

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

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

随机推荐

  1. 新建一个DataTable如何手动给其添加多条数据!

    早晨起来,想起昨天利用winform做类似于sqlserver数据库导入数据功能的时候,用到了新建一个DataTable手动给其添加多条数据,平时用不到,需要的时候想不起来了,这次不妨把他记下来.以下 ...

  2. "/Date(1405056837780)/" 时间转换

    //往往json传过来的时间都是"/Date(1405056837780)/" //转换需要的方法 String.prototype.ToString = function (fo ...

  3. c语言学习的第五天

    #include<stdio.h> #include<stdbool.h> int main() { _Bool num=1; if (num==true); { printf ...

  4. Spark RDD的依赖解读

    在Spark中, RDD是有依赖关系的,这种依赖关系有两种类型 窄依赖(Narrow Dependency) 宽依赖(Wide Dependency) 以下图说明RDD的窄依赖和宽依赖 窄依赖 窄依赖 ...

  5. js中settimeout方法加参数

    js中settimeout方法加参数的使用. 简单使用看w3school  里面没有参数调用,  例子: <script type="text/javascript"> ...

  6. 安装Spark集群(在CentOS上)

    环境:CentOS 6.4, Hadoop 1.1.2, JDK 1.7, Spark 0.7.2, Scala 2.9.3 1. 安装 JDK 1.7 yum search openjdk-deve ...

  7. ContentProvider与ContentResolver使用【转】

    这篇文章被转载而转载者未注明原文出处,在此未加上原文地址链接,本人向原作者致以歉意. 下面是文章内容: 使用ContentProvider共享数据: 当应用继承ContentProvider类,并重写 ...

  8. C# 处理csv格式的Excel文件代码

    public class CSVFileHelper { /// <summary> /// 将DataTable中数据写入到CSV文件中 /// </summary> /// ...

  9. this的使用方法

    当一个对象创建后,Java虚拟机(JVM)就会给这个对象分配一个引用自身的指针,这个指针的名字就是this.this是指向对象本身的一个指针.this只和特定的对象关联,而不和类关联,同一个类的不同对 ...

  10. .NET开源工作流RoadFlow-流程设计-流程步骤设置-按钮设置

    按钮设置是配置当前步骤的处理者可以执行哪些操作,每个按钮都有对应的执行脚本(javascript脚本). 从左边的按钮列表中选择当前步骤需要的按钮. 注意:如果是流程最后一步则要配置完成按钮而不是发送 ...