UVAL1277_Cops and Thieves
单源点汇点无向图,要阻隔某个点的流量,必须在一个点上消耗一定的价值,问你能否在消耗价值不超过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的更多相关文章
- CodeForces 689C Mike and Chocolate Thieves (二分)
原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the l ...
- CodeForces 689C Mike and Chocolate Thieves (二分+数论)
Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...
- codeforces 361 C - Mike and Chocolate Thieves
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Bad ...
- 新概念英语(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 ...
- 【Ural1277】 Cops and Thieves 无向图点连通度问题
1277. Cops and Thieves Time limit: 1.0 secondMemory limit: 64 MB The Galaxy Police (Galaxpol) found ...
- URAL 1277 - Cops and Thieves - [无向图点带权的最小点割]
题目链接:https://cn.vjudge.net/problem/URAL-1277 The Galaxy Police (Galaxpol) found out that a notorious ...
- Codeforces 689C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...
- 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 ...
- 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 ...
随机推荐
- Android广播机制简介
为什么说Android中的广播机制更加灵活呢?这是因为Android中的每个应用程序都可以对自己感兴趣的广播进行注册,这样该程序就只会接收到自己所关心的广播内容,这些广播可能是来自于系统的,也可能是来 ...
- java 进程启用远程查看
用jconsole 1.启动脚本增加: JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=192.1 ...
- windows下scrapy 的安装
2016-07-18 20:27:53 安装python 根据你的需求下载python安装包,安装python(本文基于python27)https://www.python.org/downloa ...
- 洛谷P3366 【模板】最小生成树
P3366 [模板]最小生成树 319通过 791提交 题目提供者HansBug 标签 难度普及- 提交 讨论 题解 最新讨论 里面没有要输出orz的测试点 如果你用Prim写了半天都是W- 题目 ...
- 使用maven创建web项目
eclipse 4.5.2中集成了maven,所以我们不用再去安装插件啦. 点击file->new->other->maven->maven project 选择了worksp ...
- NUGET命令
主题 about_NuGet 简短说明 提供有关 NuGet 程序包管理器命令的信息. 详细说明 本主题介绍 NuGet 程序包管理器命令.NuGet 是一种集成的程序包 管理工具,用于将库和工具添加 ...
- 如何对具有端点加密功能的LINE进行取证
LINE又有新动作了,这回默认即启用了端点加密功能,强调确保传输过程的安全,且让我们来看看如何对付新版的LINE. 有启用Letter Sealing就会在昵称前多个锁头的图像. 这手机据犯嫌供称,落 ...
- NHibernate系列文章二十六:NHibernate查询之SQL Query查询(附程序下载)
摘要 NHibernate在很早的版本就提供了SQL Query(原生SQL查询),对于很复杂的查询,如果使用其他的查询方式实现比较困难的时候,一般使用SQL Query.使用SQL Query是基于 ...
- ubuntu 开机显示错误:无法应用原保存的显示器配置
无法应用原保存的显示器配置CRTC 63:尝试 800x600@60Hz 模式输出在 1366x768@60Hz (通过 0)CRTC 63:尝试 2560x1600@60Hz 模式输出在 1366x ...
- Python2和Python3在windows下共存
Python2.7 和 Python3不兼容,两种环境可能都会用到.ubuntu14.04中已经默认安装了这两个版本,在shell中输入python会自动进入Python2.7的交互环境,输入Pyth ...