经典题,求去掉若干个点,使得两个点不在连通,总价值最少

所以拆点最小割,除了拆点边,流量都为无穷,拆点边是流量为价值

#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 最大流的更多相关文章

  1. HDU4289 Control —— 最小割、最大流 、拆点

    题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  2. HDU4289:Control(最小割)

    Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  3. hdu4289 Control 最大流最小割

    You, the head of Department of Security, recently received a top-secret information that a group of ...

  4. hdu-4289.control(最小割 + 拆点)

    Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. HDU 4289 Control(最大流+拆点,最小割点)

    题意: 有一群恐怖分子要从起点st到en城市集合,你要在路程中的城市阻止他们,使得他们全部都被抓到(当然st城市,en城市也可以抓捕).在每一个城市抓捕都有一个花费,你要找到花费最少是多少. 题解: ...

  6. 洛谷 1344 [USACO4.4]追查坏牛奶Pollutant Control——最大流

    题目:https://www.luogu.org/problemnew/show/P1344 那个边数的限制,只要把边权乘1001再+1即可.乘1001是因为有1000条边,这样流量小的不会因为边数多 ...

  7. hdu4289 Control --- 最小割,拆点

    给一个无向图.告知敌人的起点和终点.你要在图上某些点安排士兵.使得敌人不管从哪条路走都必须经过士兵. 每一个点安排士兵的花费不同,求最小花费. 分析: 题意可抽象为,求一些点,使得去掉这些点之后,图分 ...

  8. 背压(Backpressure)机制

    作者:张铁蕾链接:https://www.zhihu.com/question/49618581/answer/117107570来源:知乎著作权归作者所有,转载请联系作者获得授权. 首先,从大的方面 ...

  9. qt Multimedia 模块类如何使用?

    qt 多媒体模块介绍 类名 英文描述 中文描述 QAudioBuffer Represents a collection of audio samples with a specific format ...

随机推荐

  1. Unity3d本地存储

    原文地址:http://blog.csdn.net/dingkun520wy/article/details/49386507 (一)简单数据存储PlayerPrefs 这种存储方法比较简单直接上代码 ...

  2. 硬盘4k对齐教程总结

    4k对齐概念: 4K对齐相关联的是一个叫做“高级格式化”的分区技术.首先先来了解一下什么是叫做“4K 对齐”.其实“4K对齐”相关联的是一个叫做“高级格式化”的分区技术.“高级格式化”是国际硬盘设备与 ...

  3. jquery pass parameter to ajax callback

    $('.del').on('click', function () { var id = $(this).attr('id'); var url = '/m/g2_content_del/' + id ...

  4. 使用 PIVOT 和 UNPIVOT

    http://msdn.microsoft.com/zh-cn/library/ms177410%28v=SQL.90%29.aspx 可以使用 PIVOT 和 UNPIVOT 关系运算符将表值表达式 ...

  5. zoj 3620 Escape Time II dfs

    题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...

  6. IsBadReadPtr|IsBadWritePtr调试崩溃

    遇到一未找到必然出现条件的崩溃,不知道什么时候能触发崩溃,崩溃dump显示,试图访问了非法的内存或者写入了非法的内存 此时如下两个函数就比较有用了: BOOL WINAPI IsBadReadPtr( ...

  7. Android 国际化文字

    本例演示中英文切换 在resource文件夹添加values-zh,这个文件夹对应中文环境的values文件夹,然后添加strings.xml: <?xml version="1.0& ...

  8. Android SlidingMenu的getSupportActionBar无法找到的解决

    getSupportActionBar()方法不能用 进入Library中的src下找到SlidingFragmentActivity.java,修改 public class SlidingFrag ...

  9. UR #13 Yist

    第一次打UR,打了一个半小时就弃疗了QAQ 这是我唯一一道考试的时候做出来的题目,其他两道连暴力都懒得写了 很容易发现对于每个要删除的点 我们找到左边第一个比他小的不用删除的点,右边第一个比他小的不用 ...

  10. POJ 2778 DNA sequence

    QAQ 做完禁忌 又做过文本生成器 这道题就是个水题啦 首先转移方程还是文本生成器的转移方程 但是注意到L很大,但是节点数很小 转移都是固定的,所以我们可以用AC自动机来构造转移矩阵 之后进行矩阵乘法 ...