单源点汇点无向图,要阻隔某个点的流量,必须在一个点上消耗一定的价值,问你能否在消耗价值不超过k的前提下,阻隔源点到汇点的流量。

直接对于有权值的点拆点,拆后边容量即为点权。其余的点的容量无穷,最大流即可。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 5555
#define maxm 555555
using namespace std; const int inf=;
int to[maxm],c[maxm],next[maxm],first[maxn],edge;
int a[maxn],d[maxn],tag[maxn],TAG=;
bool can[maxn];
int Q[maxm],bot,top;
int n,m,l,s,t; void _init()
{
edge=-;
for (int i=; i<=n+n; i++) first[i]=-;
} void addedge(int U,int V,int W)
{
edge++;
to[edge]=V,c[edge]=W,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} bool bfs()
{
Q[bot=top=]=t,tag[t]=++TAG,d[t]=,can[t]=false;
while (bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
if (c[i^] && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,d[to[i]]=d[cur]+;
can[to[i]]=false,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int i=first[cur]; i!=-; i=next[i])
if (c[i] && d[to[i]]==d[cur]- && tag[to[i]]==TAG && !can[to[i]])
{
k=dfs(to[i],min(c[i],num));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (!num) break;
}
if (num) can[cur]=true;
return tmp-num;
} int main()
{
int U,V,Flow,K;
while (scanf("%d",&K)!=EOF)
{
scanf("%d%d%d%d",&n,&m,&s,&t);
for (int i=; i<=n; i++) scanf("%d",&a[i]);
_init();
for (int i=; i<=m; i++)
{
scanf("%d%d",&U,&V);
addedge(U+n,V,inf),addedge(V+n,U,inf);
}
if (s==t)
{
puts("NO");
continue;
}
s+=n;
for (int i=; i<=n; i++) addedge(i,i+n,a[i]);
for (Flow=; Flow<=K && bfs(); bfs()) Flow+=dfs(s,inf);
if (K>=Flow) puts("YES");
else puts("NO");
}
return ;
}

UVAL1277_Cops and Thieves的更多相关文章

  1. CodeForces 689C Mike and Chocolate Thieves (二分)

    原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the l ...

  2. CodeForces 689C Mike and Chocolate Thieves (二分+数论)

    Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...

  3. codeforces 361 C - Mike and Chocolate Thieves

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad ...

  4. 新概念英语(1-119)who call out to the thieves in the dark?

    who call out to the thieves in the dark? A true story Do you like stories? I want to tell you a true ...

  5. 【Ural1277】 Cops and Thieves 无向图点连通度问题

    1277. Cops and Thieves Time limit: 1.0 secondMemory limit: 64 MB The Galaxy Police (Galaxpol) found ...

  6. URAL 1277 - Cops and Thieves - [无向图点带权的最小点割]

    题目链接:https://cn.vjudge.net/problem/URAL-1277 The Galaxy Police (Galaxpol) found out that a notorious ...

  7. Codeforces 689C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...

  8. Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...

  9. ZeptoLab Code Rush 2015 A. King of Thieves 暴力

    A. King of Thieves Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526/pr ...

随机推荐

  1. Python招聘需求与技能体系

    目前国内的招聘Python,基本都是偏向web后台开发,偶有高大上的数据挖掘&机器学习. 这是之前(2012年)找工作整理的一些JD,在梳理几年来的笔记,顺带理一理 可以以此建立自己的技能体系 ...

  2. eclipse中提示HttpServletRequest不能引用的解决办法

    两种解决方法: 1.右键点击项目->Build Path->Add Libraries..->Server Runtime 选择Apache Tomcat v8.0 2.右键点击项目 ...

  3. Flash插件地址

    Flash插件地址: http://get.adobe.com/cn/flashplayer/存档版本地址: http://helpx.adobe.com/flash-player/kb/archiv ...

  4. PHP使用feof()函数读文件的方法

    这篇文章主要介绍了PHP使用feof()函数读文件的方法,以实例形式对比了正确与错误的用法,阐明了feof()函数的使用技巧,需要的朋友可以参考下 本文实例讲述了PHP使用feof()函数读文件的方法 ...

  5. CSS :hover伪类选择定义和用法

    伪类选择符E:hover的定义和用法: 设置元素在其鼠标悬停时的样式.E元素可以通过其他选择器进行选择,比如使用类选择符.id选择符.类型选择符等等.特别说明:IE6并非不支持此选择符,但能够支持a元 ...

  6. 创建sa账号

    ①以windows身份验证的方式默认登陆 ②选择安全性下的登录名中的sa账号,右键选择属性,进行相关项的设置 ③将sa账号的状态中对应的登录项由之前的禁用,改为已启用 ④将sa对应的密码进行修改为自己 ...

  7. 关于Listview布局的一点经验

    1.尽量是给item一个固定高度,最外层不要设高度,里面套一层设置一个固定高度:如果用wrap_content的话,之后用alignTop等会出奇怪的问题. 2.如果要使用alignTop align ...

  8. 链接测试工具xenu link sleuth的使用

    链接测试工具xenu link sleuth的使用很简单. 可以从这里下载 http://home.snafu.de/tilman/xenulink.html 但是注意到: 如果需要登录才能进入所有的 ...

  9. 【转】提高VR渲染速度的最好方法(经典转载)

    VR的基本渲染方法掌握起来并不难,但是最迫切需要解决的问题是VR的出图速度问题.动则需要数小时的渲染时间真的是很难以接受,我们从三个影响速度的参数结合网上一些高手的教程来分析一下. 一.Irradia ...

  10. 轻量数据交换json,xml,ini

    json语法: object   {string:value,...} value   string/number/object/array/true/false/null array   value ...