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

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

#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. Sql之表的连接总结

    1.交叉连接(就是将两张表的数据 交叉组合在一起) 有两张表 客户表:[Sales.Customers] 和订单表:[Sales.Orders]. 业务需求:实现 Customer中custid(客户 ...

  2. 扫盲Linq知识

    LINQ,语言集成查询(Language Integrated Query),是在.NET Framework 3.5 中出现的技术. 借助于LINQ技术,我们可以使用一种类似SQL的语法来查询任何形 ...

  3. Notepad++ 右键菜单自定义配置

    问:想在右键菜单里面多加几个功能,怎么加,比如区块注释 答:其实notepad++的配置文件存放路径不在自己的软件路径,而存在于 xp:C:\Documents and Settings\Admini ...

  4. spoj 297

    就是对距离进行二分找最大值 .... #include <cstring> #include <cstdio> #include <algorithm> #incl ...

  5. linux下mysql修改数据库账户root密码

    #先停止mysql,再运行下一句 $ mysqld_safe --user=mysql --skip-grant-tables --skip-networking & $ mysql -u r ...

  6. 【疯狂Java讲义学习笔记】【数据类型与运算符】

    [学习笔记]1.8bit = 1byte,4byte = 1word.Java中的整型数据有byte(1字节),short(2字节),int(4字节),long(8字节).Java中的浮点数据有flo ...

  7. 我见过的 Objective-C, 讲的最通俗易懂的入门教程....

    http://www.cnblogs.com/mjios/category/454764.html  ---- 给力...

  8. win7下VS.NET中通过LinqToSQL连接oracle数据库

    .NetFramework3.5提供了LinqToSQL组件,为我们访问数据库提供了方便.我用的是VS+Oracle开发工具.也想体验一下快捷方便的感觉. 1.连接Oracle数据库 在连接Oracl ...

  9. 简单的ftpserver设置

    一.安装: yum install vsftpd* 二. 修改配置文档如下: vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO chroot_list_en ...

  10. 【ZOJ】2112 Dynamic Rankings

    树状数组套主席树模板题目. /* 2112 */ #include <iostream> #include <sstream> #include <string> ...