题目链接: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. Filestream读取或写入文件

    using System.IO;//引用 System.IO namespace filestream { public partial class Form1 : Form { public For ...

  2. Log4net使用笔记

    Log4net使用笔记   编写人:CC阿爸 2013-10-29 近来在处理项目时候,想将系统的操作日志以文本的形式记录下来,方便对系统操作记录进行追踪. 经过在网上搜索部分解决方案,大致可以归纳如 ...

  3. Cassandra 的压缩策略STCS,LCS 和 DTCS

    更新说明: 本文编写时最新的Cassandra版本为2.2,最新的稳定版本为2.1.8 2016年6月23日,增加一篇译文,当下最新版本为3.7 最新的Cassandra 2.1 或者更高的版本支持3 ...

  4. Python 字典(Dictionary)操作详解

    Python 字典(Dictionary)的详细操作方法. Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串.数字.元组等其他容器模型. 一.创建字典 字典由键和对应值成对组成.字 ...

  5. VC++ 在类中添加多线程操作

    CTestThread.h public: CTestThread(void); ~CTestThread(void); public: void setvalue(); static DWORD _ ...

  6. Windows7下CHM电子书打开不能正常显示内容

    Author:KillerLegend Date:2014.1.28 Welcome to my blog:http://www.cnblogs.com/killerlegend/ 今日下载一个CHM ...

  7. 数据结构学习笔记05图 (邻接矩阵 邻接表-->BFS DFS、最短路径)

    数据结构之图 图(Graph) 包含 一组顶点:通常用V (Vertex) 表示顶点集合 一组边:通常用E (Edge) 表示边的集合 边是顶点对:(v, w) ∈E ,其中v, w ∈ V 有向边& ...

  8. vim之旅

    本人是今年的毕业生, 大学很莫名的选择了一个电子商务专业. 由于专业没有实质性的东西可学,加上对电商不敢兴趣, 于是乎我有了大量的时间在宿舍里折腾电脑. 折腾了几年大三决定转业, 大四在还没找工作之前 ...

  9. windows下python+flask环境配置详细图文教程

    本帖是本人在安装配置python和flask环境时所用到的资源下载及相关的教程进行了整理罗列,来方便后面的人员,省去搜索的时间.如果你在安装配置是存在问题可留言给我. 首先罗列一下python+fla ...

  10. GNU make 规则

    clean : rm *.tmp 规则格式: targets : prerequisites recipe ... targets : prerequisites : recipe recipe .. ...