HDU4289 Control 最大流
经典题,求去掉若干个点,使得两个点不在连通,总价值最少
所以拆点最小割,除了拆点边,流量都为无穷,拆点边是流量为价值
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long LL;
const int maxn=4e2+;
const int INF=0x3f3f3f3f;
struct Edge
{
int from,to,cap,flow;
Edge(int u,int v,int c,int d):from(u),to(v),cap(c),flow(d) {}
};
struct dinic
{
int s,t;
vector<Edge>edges;
vector<int>G[maxn];
int d[maxn];
int cur[maxn];
bool vis[maxn];
void init(){
edges.clear();
for(int i=;i<maxn;++i)
G[i].clear();
}
bool bfs()
{
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
d[s]=;
vis[s]=;
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=; i<G[x].size(); i++)
{
Edge &e= edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=;
d[e.to]=d[x]+;
q.push(e.to);
}
}
}
return vis[t];
}
int dfs(int x,int a)
{
if(x==t||a==)return a;
int flow=,f;
for(int &i=cur[x]; i<G[x].size(); i++)
{
Edge &e=edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow))))
{
e.flow+=f;
edges[G[x][i]^].flow-=f;
flow+=f;
a-=f;
if(a==)break;
}
}
return flow;
}
int maxflow(int s,int t)
{
this->s=s;
this->t=t;
int flow=;
while(bfs())
{
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
void addedge(int u,int v,int c)
{
Edge x(u,v,c,),y(v,u,,);
edges.push_back(x);
edges.push_back(y);
int l=edges.size();
G[u].push_back(l-);
G[v].push_back(l-);
}
}solve;
int a[maxn/];
int main()
{
int n,m,s,t;
while(~scanf("%d%d",&n,&m)){
scanf("%d%d",&s,&t);
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
solve.init();
for(int i=;i<=m;++i){
int u,v;
scanf("%d%d",&u,&v);
solve.addedge(u+n,v,INF);
solve.addedge(v+n,u,INF);
}
for(int i=;i<=n;++i)
solve.addedge(i,i+n,a[i]);
printf("%d\n",solve.maxflow(s,t+n));
}
return ;
}
HDU4289 Control 最大流的更多相关文章
- HDU4289 Control —— 最小割、最大流 、拆点
题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU4289:Control(最小割)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu4289 Control 最大流最小割
You, the head of Department of Security, recently received a top-secret information that a group of ...
- hdu-4289.control(最小割 + 拆点)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 4289 Control(最大流+拆点,最小割点)
题意: 有一群恐怖分子要从起点st到en城市集合,你要在路程中的城市阻止他们,使得他们全部都被抓到(当然st城市,en城市也可以抓捕).在每一个城市抓捕都有一个花费,你要找到花费最少是多少. 题解: ...
- 洛谷 1344 [USACO4.4]追查坏牛奶Pollutant Control——最大流
题目:https://www.luogu.org/problemnew/show/P1344 那个边数的限制,只要把边权乘1001再+1即可.乘1001是因为有1000条边,这样流量小的不会因为边数多 ...
- hdu4289 Control --- 最小割,拆点
给一个无向图.告知敌人的起点和终点.你要在图上某些点安排士兵.使得敌人不管从哪条路走都必须经过士兵. 每一个点安排士兵的花费不同,求最小花费. 分析: 题意可抽象为,求一些点,使得去掉这些点之后,图分 ...
- 背压(Backpressure)机制
作者:张铁蕾链接:https://www.zhihu.com/question/49618581/answer/117107570来源:知乎著作权归作者所有,转载请联系作者获得授权. 首先,从大的方面 ...
- qt Multimedia 模块类如何使用?
qt 多媒体模块介绍 类名 英文描述 中文描述 QAudioBuffer Represents a collection of audio samples with a specific format ...
随机推荐
- Ubuntu 设置root用户登录
由于 Ubuntu 是基于 Debian 的 linux 操作系统,在默认的情况下,是没有超级用户(superuser, root)的,但有些系统操作必须有超级用户的权限才能进行,如手动释放内存等. ...
- 简单的SQL Server在线查看和执行系统
在大的公司里面,往往数据库和表都非常的多,一张表的字段也是会有几十个.如果这么多的表和字段没有说明注释的话,查看起来会一头雾水,新来的或者别的部门的同事看到表和字段会完全不知道是干嘛的,只能靠名称来猜 ...
- java 凯撒大帝密码
古罗马皇帝凯撒在打仗时曾经使用过以下方法加密军事情报:
- webstorm 11 安装配置 grunt 时遇到的问题及解决办法
想学grunt的可以看看这篇文章,写的很有意思,教程之类的我就不写了,网上很多资料,我就记录下我遇到的问题和解决办法. http://yujiangshui.com/grunt-basic-tutor ...
- ExtJS4.2学习(18)时间控件(转)
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-12-22/190.html 感谢“束洋洋 ”的付出. 前言 ...
- 搭建 Android 开发环境,初试HelloWorld (win7) (下) (转)
5. 创建AVD 为使Android应用程序可以在模拟器上运行,必须创建AVD. 在Eclipse菜单中,选择 Windows -> Android Virtual Device Manage ...
- spoj 362
规律还是比较好找的 大数除法 #include <cstdio> #include <cstring> int len,a[1000],q; int cc[] = {0,1, ...
- oracle SQLserver 函数
1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) S:select ceiling(-1.001) value ...
- python参考手册--第9章
1.读取命令行选项 (1)sys.args python启动时,命令行选项设置在列表sys.args中. sys.args[0]:xxx.py sys.args[1:]: 其他参数 (2)optpar ...
- Pie Charts
Default pie chart The default pie chart with no options set. Source Code $.plot('#placeholder', da ...