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 ...
随机推荐
- 慕客网laravel学习笔记
session中set方法使用 Session::set('user.username.age','18')嵌套使用得出$user = ['username'=>['age'=>18]]; ...
- Haproxy+asp.net +RedisSessionStateProvider 完美实现负载均衡,并且session保持
.net framework 4.5下测试成功,使用RedisSessionStateProvider 2.2.1保持session数据,通过Haproxy保持会话数据.首先在PM下安装RedisSe ...
- 我的ZJ解题心得
想要学好程序设计第一是要养成你的编程思维,也就是你对编程的一种概念和思维定式,长期的解题会让你产生解题经验进而形成一种思维定式,比如看到一个题目就立即想出这题要用什么方法解题这样.编程思维我认为还包括 ...
- 如何修改SharePoint列表条数等阈值
若要修改SharePoint中对列表最大条数等设定的阈值,可按如下步骤操作: 1. 打开页面:管理中心 > 应用程序管理 > 管理Web应用程序.2. 选择要修改阈值的Web应用程序,并在 ...
- osmdroid启程
osmdroid一个牛逼的开源地图引擎,从今天开始好好研究一下~
- iOS官方Sample大全
转载自:http://blog.csdn.net/yangtb2010/article/details/7005471 http://developer.apple.com/library/ios/s ...
- ASP.NET Page对象各事件执行顺序(转)
很久没写 asp.net 的东西了,search 了一下 page 的事件执行顺序,找到如下的东西,仅仅做记录用 Page.PreInit 在页初始化开始时发生 Page.Init 当服务器控件初始化 ...
- LCD1602写自定义字符的Verilog源码
开发工具:Quartus II 9.1: 仿真软件:Questa Sim 10.0c: 硬件平台:Terasic DE2-115(EP2C35F672C6): 外设:hd44780控制器lcd1602 ...
- Spark Streaming源码解读之流数据不断接收全生命周期彻底研究和思考
本期内容 : 数据接收架构设计模式 数据接收源码彻底研究 一.Spark Streaming数据接收设计模式 Spark Streaming接收数据也相似MVC架构: 1. Mode相当于Rece ...
- git 放弃本地修改 强制更新
git reset --hard origin/master