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 ...
随机推荐
- 未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项
当前系统环境描述: Win7x64+VS2012+IIS7 当前情况描述: 发布Web服务,在浏览的时候出现以下问题:未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, ...
- echarts简单使用案例
先上效果图:
- Java垃圾回收基础
- 关于commons-fileupload组件上传文件中文名乱码问题
java web开发,常用到的文件上传功能,常用的commons-fileupload和commons-io两个jar包.关于如何使用这两个jar来完成文件上传的功能,这里不做详解.使用commons ...
- dede 单表模型动态浏览设置 arclistsg arc.sglistview.class.php
比如,分类信息,内容页默认都是生成静态的,如果有需要设为动态访问的,可以参考如下方法: arclistsg 标签,单表独立模型的文档列表调用标记 方法一: 在arclist标签使用中,其对应主表ded ...
- 3)Java容器
3)Java容器 Java的集合框架核心主要有三种:List.Set和Map.这里的 Collection.List.Set和Map都是接口(Interface). List lst = new ...
- C# 文件流基本操作步骤
private void button1_Click(object sender, EventArgs e) { FileStream fs = new FileStream("123.tx ...
- C#发送邮件源码
介绍 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.SMTP协议属于TCP/IP协议 ...
- WPF:将HTML RGB颜色值转化为Color对象的两种方式
(1)方式一: Color color1 = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#E0E0E0&qu ...
- Java入门到精通——基础篇之static关键字
一.概述 static 关键字是声明静态变量,静态方法用的.static的含义是属于类且不属于类对象的变量和函数. 二.static的产生. 在创建对象的时候除非用new ...