hdu 3549 Flow Problem 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549
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)
#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 网络流的更多相关文章
- HDU 3549 Flow Problem 网络流(最大流) FF EK
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- 网络流 HDU 3549 Flow Problem
网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu 3549 Flow Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Description Network flow is a well- ...
- hdu 3549 Flow Problem【最大流增广路入门模板题】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others ...
- HDU 3549 Flow Problem(最大流模板)
http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include< ...
- hdu 3549 Flow Problem Edmonds_Karp算法求解最大流
Flow Problem 题意:N个顶点M条边,(2 <= N <= 15, 0 <= M <= 1000)问从1到N的最大流量为多少? 分析:直接使用Edmonds_Karp ...
- hdu 3549 Flow Problem (网络最大流)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- HDU 3549 Flow Problem (最大流ISAP)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
随机推荐
- 单个input框上传多个文件操作
HTML页面: <div class="form-group thumb"> <label class="control-label col-xs-12 ...
- Spark官方文档——独立集群模式(Standalone Mode)
除了部署在Mesos之上, Spark也支持独立部署模式,包括一个Spark master进程和多个 Spark worker进程.独立部署模式可以运行在单机上作为测试之用,也可以部署在集群上.如果你 ...
- mssql 下删除 default 值的Sql写法
FROM Sys.default_constraints a JOIN sys.columns b ON a.parent_object_id = b.object_id AND a.parent_c ...
- C# 调用系统API 内核 简单样例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- Python核心编程--学习笔记--2--Python起步(下)
16 文件和内建函数open(),file() 打开文件: fobj = open(filename, 'r') for eachLine in fobj: print eachLine, #由于每行 ...
- char const*, char*const, const char *const的区别
C++标准规定,const关键字放在类型或变量名之前等价的.所以,const char*和 char const*是一样的. const char* //常量指针---指向常量的指针----指针指 ...
- C++经典书籍推荐
<C++程序设计语言> <C++语言设计与演化> <C++标准程序库> <EFFECTIVE C++ 中文版> <MORE EFFECTIVE C ...
- bat完美关机命令
@echo off title OLIVER-COMPUTER mode con cols= lines= color 0d shutdown /a >nul >nul ver > ...
- core java 1~4(HelloWorld & 标识符|关键字|数据类型 & 表达式|流程控制 & 数组)
MODULE 1 Java的编译和运行----------------------------编译:javac -d bin src\HelloWorld.java -d:指定编译后的class 文件 ...
- asp.net实现手机号码归属地查询,代码如下
protected void Button1_Click(object sender, EventArgs e) { if (Regex.IsMatch(TextB ...