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 图片进度条
png图片 代码 ImageView loading=getActivity().findViewById(R.id.pro_loading); LinearInterpolator lin = ne ...
- [vB.NET]为控件添加鼠标悬浮时的提示气泡
实例代码: Dim k As ToolTip k = New ToolTip() k.AutoPopDelay = '显示出气泡后的延时时间(毫秒) k.InitialDelay = '出现前的延时( ...
- linux下查找某个文件位置的方法
一.通过文件名查找法: 举例说明,假设你忘记了httpd.conf这个文件在系统的哪个目录 下,甚至在系统的某个地方也不知道,则这是可以使用如下命令: find / -name httpd.conf ...
- [Jquery] Jquery AutoComplete的使用方法实例
jQuery的Autocomplete(自动完成.自动填充)插件 jquery-autocomplete配置: <script type="text/javascript" ...
- Linux系统man查询命令等级及意义
1:用户命令,可由任何人启动的 2:系统调用,由内核提供的函数 3:库函数 4:设备,/dev目录下的特殊文件 5:文件格式描述,例如/etc/passwd 6:游戏 7:杂项,例如宏命令包.惯例等 ...
- 第十六章 综合实例——《跟我学Shiro》
简单的实体关系图 简单数据字典 用户(sys_user) 名称 类型 长度 描述 id bigint 编号 主键 username varchar 100 用户名 password varchar 1 ...
- DescriptionResourcePathLocationType Dynamic Web Module 3.0 requires Java
先保证ide的所有jdk都在1.6及以上,如果还是错就试试下面的 在<build></build>中添加 <plugins> <plugin> < ...
- C语言的time.h解释python的time
clock_t clock(void),对比python的clock() 返回程序执行的时间,clock_t的实际类型是long #include<Windows.h> Sleep(); ...
- Variant OLE automation
The Variant data type is the data type for all variables. can contain any kind of data except fixed- ...
- 64 位 Ubuntu 下 android adb 不可用解决方法
解决方案: 安装ia32-libs 在终端执行 sudo apt-get install ia32-libs 其间会提示所依赖的某些包不存在,直接 sudo apt-get 安装即可.