hdu 4289 Control 网络流
给出一些点, 每个点有一个权值, 给出一些边, 起点以及终点, 去掉一些点使得起点和终点不连通, 求最小的val。
拆点, 把一个点s拆成s和s', 之间建一条边, 权值为点权。 对于一条边, <u, v> 建边<u, v'>, <v, u'> 权值为inf, 跑一遍最大流。
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxx = ;
const int maxn = ;
int head[maxn*], s, t, num, q[maxn*], dis[maxn];
struct node
{
int to, nextt, c;
}e[maxn*];
void init() {
mem1(head);
num = ;
}
void add(int u, int v, int c) {
e[num].to = v; e[num].nextt = head[u]; e[num].c = c; head[u] = num++;
e[num].to = u; e[num].nextt = head[v]; e[num].c = ; head[v] = num++;
}
int bfs() {
int u, v, st = , ed = ;
mem(dis);
dis[s] = ;
q[ed++] = s;
while(st<ed) {
u = q[st++];
for(int i = head[u]; ~i; i = e[i].nextt) {
v = e[i].to;
if(e[i].c&&!dis[v]) {
dis[v] = dis[u]+;
if(v == t)
return ;
q[ed++] = v;
}
}
}
return ;
}
int dfs(int u, int limit) {
if(u == t)
return limit;
int cost = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(e[i].c&&dis[u] == dis[v]-) {
int tmp = dfs(v, min(limit-cost, e[i].c));
if(tmp>) {
e[i].c -= tmp;
e[i^].c += tmp;
cost += tmp;
if(cost == limit)
break;
} else {
dis[v] = -;
}
}
}
return cost;
}
int dinic() {
int ans = ;
while(bfs()) {
ans += dfs(s, inf);
}
return ans;
}
int main()
{
int n, m, val, x, y;
while(cin>>n>>m) {
cin>>s>>t;
t+=n;
init();
for(int i = ; i<=n; i++) {
scanf("%d", &val);
add(i, i+n, val);
}
while(m--) {
scanf("%d%d", &x, &y);
add(x+n, y, inf);
add(y+n, x, inf);
}
int ans = dinic();
cout<<ans<<endl;
}
}
hdu 4289 Control 网络流的更多相关文章
- HDU 4289 Control (网络流,最大流)
HDU 4289 Control (网络流,最大流) Description You, the head of Department of Security, recently received a ...
- hdu 4289 Control(最小割 + 拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 Control Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 4289 Control (最小割 拆点)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 4289 Control 最小割
Control 题意:有一个犯罪集团要贩卖大规模杀伤武器,从s城运输到t城,现在你是一个特殊部门的长官,可以在城市中布置眼线,但是布施眼线需要花钱,现在问至少要花费多少能使得你及时阻止他们的运输. 题 ...
- HDU 4289 Control
最小割 一个点拆成两个 AddEdge(i,i+N,x); 原图中的每条边这样连 AddEdge(u+N,v,INF); AddEdge(v+N,u,INF); S是源点,t+N是汇点.最大流就是答案 ...
- HDU - 4289 Control (Dinic)
You, the head of Department of Security, recently received a top-secret information that a group of ...
- HDU 4289 Control(最大流+拆点,最小割点)
题意: 有一群恐怖分子要从起点st到en城市集合,你要在路程中的城市阻止他们,使得他们全部都被抓到(当然st城市,en城市也可以抓捕).在每一个城市抓捕都有一个花费,你要找到花费最少是多少. 题解: ...
- hdu 4289 最大流拆点
大致题意: 给出一个又n个点,m条边组成的无向图.给出两个点s,t.对于图中的每个点,去掉这个点都需要一定的花费.求至少多少花费才能使得s和t之间不连通. 大致思路: 最基础的拆点最大 ...
- (网络流 最大流 Dinic || SAP)Control -- hdu --4289
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4289 http://acm.hust.edu.cn/vjudge/contest/view.action ...
随机推荐
- Oracle EBS Concurrent Request:Gather Schema Statistics[Z]
Oracle EBS 的Concurrent Request"Gather Schema Statistics"是一个和性能相关的Concurrent Program,它会对表,列 ...
- js——BOM
BOM:Browser Object Model 浏览器对象模型 open(页面的地址url,打开的方式) :方法 打开一个新的窗口(页面) 如果url为空,折磨人打开一个空白页面 如果打开方式为 ...
- 编程实现任意长度整数的加法(整数可以长度超出C++中int范围)
#include <iostream> #include<string> using namespace std; string add(string s1,string s2 ...
- QF——关于iOS的强引用,弱引用及strong,retain,copy,weak,assignd的关系
强引用和弱引用: 我们已经知道OC中的内存管理是通过“引用计数器”来实现的.一个对象的生命周期取决于它是否还被其他对象引用(是否retainCount=0).但在有些情况下,我们并不希望对象的销毁时间 ...
- php curl函数实例
<?php function login(){ $url = 'http://jspatch.qq.com/offline/check?qver=6.2.0.427&hver=0& ...
- PHP EOF(heredoc)的使用
<?php /* Heredoc技术,在PHP手册和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术. 目前一些论坛程序和CMS系统使用了这种技术,前不久看一个朋友的P ...
- 解决Qt程序发布时中文乱码问题(通过QApplication.addLibraryPath加载QTextCodec插件)
Qt程序的文字编码,是通过插件来解决的,所以我们发布的时候需要把相应的插件也发布出去,在开发者电脑上程序会自动从插件目录加载到插件,但是如果发布给别的电脑使用,需要手动指定插件路径,如下所示: int ...
- c语言libcurl 使用实例get/post方法+c语言字符串处理
#include <stdio.h> #include <curl/curl.h> #include <string.h> #include <ctype.h ...
- MFC DLL资源动态切换
在MFC使用过程中,遇到DLL资源与主EXE资源冲突问题. 出现这样的Bug,一时无从下手. 报错位置在核心代码中dlgcore.cpp. [cpp] view plaincopy BOOL AFXA ...
- 使用MD5完成自定义Person对象的加密过程
---恢复内容开始--- 首先:我们对自定义Person对象的加密过程所用的方法是归档写入文件的方法. 第一步:创建Person,继承于NSObject,然后在Person.h文件遵守NSCoding ...