hdu 3549 Flow Problem (最大流)
裸最大流,做模板用
m条边,n个点,求最大流
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm> using namespace std; const int N = ;
const int INF = 0x7fffffff; int flow[N];
int cap[N][N];
int pre[N]; queue<int>q; int m, n; int BFS(int src, int des)
{
while (!q.empty()) q.pop();
for (int i = ; i <= n; ++i) pre[i] = -;
flow[src] = INF;
pre[src] = ;
q.push(src);
while (!q.empty()) {
int index = q.front();
q.pop();
if (index == des) break;
for (int i = ; i <= n; ++i) {
if (pre[i] == - && cap[index][i] > ) {
pre[i] = index;
flow[i] = min(cap[index][i], flow[index]);
q.push(i);
}
}
}
if (pre[des] == -) return -;
return flow[des];
} int maxFlow(int src, int des)
{
int ans = ;
int in = ;
while ((in = BFS(src, des)) != -) {
int k = des;
while (k != src) {
int last = pre[k];
cap[last][k] -= in;
cap[k][last] += in;
k = last;
}
ans += in;
}
return ans;
} int main()
{
int t;
int i, k;
scanf("%d", &t);
for (k = ; k <= t; ++k) {
memset(cap, , sizeof cap);
memset(flow, , sizeof flow);
scanf("%d%d", &n, &m);
for (i = ; i < m; ++i) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
cap[a][b] += c;
}
printf("Case %d: %d\n", k, maxFlow(, n));
}
return ;
}
hdu 3549 Flow Problem (最大流)的更多相关文章
- hdu - 3549 Flow Problem (最大流模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...
- hdu 3549 Flow Problem 最大流 Dinic
题目链接 题意 裸的最大流. 学习参考 http://www.cnblogs.com/SYCstudio/p/7260613.html Code #include <bits/stdc++.h& ...
- 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
网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...
- 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 Flow Problem Description Network flow is a well- ...
- HDU 3549 Flow Problem (最大流ISAP)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- hdu 3549 Flow Problem Edmonds_Karp算法求解最大流
Flow Problem 题意:N个顶点M条边,(2 <= N <= 15, 0 <= M <= 1000)问从1到N的最大流量为多少? 分析:直接使用Edmonds_Karp ...
- HDU 3549 Flow Problem 网络流(最大流) FF EK
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
随机推荐
- Java基础知识学习
1.什么是Java编程语言 Java是:一种编程语言.一种开发环境.一种应用环境.一种部署环境 2.Java编程语言的主要目标 (1)提供一种解释环境为:提高开发速度.代码可移植性.使用户能运行不止一 ...
- iOS 后台运行实现 --备用
文一 我从苹果文档中得知,一般的应用在进入后台的时候可以获取一定时间来运行相关任务,也就是说可以在后台运行一小段时间. 还有三种类型的可以运行在后以,1.音乐2.location 3.voip 文二 ...
- 使用text-overflow:ellipsis对溢出文本显示省略号有两个好处
使用text-overflow:ellipsis对溢出文本显示省略号有两个好处,一是不用通过程序限定字数:二是有利于SEO.需要使用对对溢出文本显示省略号的通常是文章标题列表,这样处理对搜索引擎更友好 ...
- xss攻击入门
xss表示Cross Site Scripting(跨站脚本攻击),它与SQL注入攻击类似,SQL注入攻击中以SQL语句作为用户输入,从而达到查询/修改/删除数据的目的,而在xss攻击中,通过插入恶意 ...
- 增加Android可用内存
In the development of TV applications, especially when dealing with images were more likely to feel ...
- 【NOIP 2014 DAY1 T3】飞扬的小鸟(DP)
题目描述 Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管或者掉在地上的话,便 ...
- linux相关办公软件汇总
ubuntu pdf阅读器 FoxitReader_1.1.0_i386.deb ubuntu 下的PDF阅读器(超级好使) Ubuntu下的chm和PDF阅读器 ubuntu便签软件xpad sud ...
- C# Http请求(GET/HTTP/HTTPS)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
- Android开发规范
一.Android编码规范 1.java代码中不出现中文,最多注释中可以出现中文 2.局部变量命名.静态成员变量命名 只能包含字母,单词首字母出第一个外,都为大写,其他字母都为小写 3.常量命名 只能 ...
- BNU29368:Check the Identity(栈)
Just determine whether an algebraic expression can always simplify to zero. Input The first line con ...