URAL1277 Cops and Thieves(最小割)
Cops and Thieves
Description:
10
5 5 1 5
1 6 6 11 1
1 2
1 3
2 4
3 4
4 5
NO
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = ,M = 1e5+;
int n,m,s,F,tot,k;
int w[N],head[N],d[N];
struct Edge{
int u,v,c,next;
}e[M];
void adde(int u,int v,int c){
e[tot].v=v;e[tot].next=head[u];e[tot].c=c;head[u]=tot++;
e[tot].v=u;e[tot].next=head[v];e[tot].c=;head[v]=tot++;
}
int bfs(){
memset(d,,sizeof(d));d[F]=;
queue <int > q;q.push(F);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(e[i].c> && !d[v]){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[s+n]!=;
}
int dfs(int S,int a){
if(S==s+n || a==) return a;
int flow=,f;
for(int i=head[S];i!=-;i=e[i].next){
int v=e[i].v;
if(d[v]!=d[S]+) continue ;
f=dfs(v,min(a,e[i].c));
if(f>){
e[i].c-=f;
e[i^].c+=f;
flow+=f;
a-=f;
if(a==) break;
}
}
if(!flow) d[S]=-;
return flow;
}
int Dinic(int S,int T){
int flow = ;
while(bfs())
flow+=dfs(S,INF);
return flow ;
}
int main(){
cin>>k>>n>>m>>s>>F;
memset(head,-,sizeof(head));
for(int i=;i<=n;i++) scanf("%d",&w[i]);
for(int i=;i<=n;i++){
if(i==s ||i==F) adde(i,i+n,INF);
else adde(i,i+n,w[i]);
}
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
adde(u+n,v,INF);adde(v+n,u,INF);
}
int flow = Dinic(F,s+n);
if(flow>k) cout<<"NO";
else cout<<"YES";
return ;
}
URAL1277 Cops and Thieves(最小割)的更多相关文章
- HDU3870-Caught these thieves(最小割->偶图->最短路问题)
A group of thieves is approaching a museum in the country of zjsxzy,now they are in city A,and the m ...
- 【Ural1277】 Cops and Thieves 无向图点连通度问题
1277. Cops and Thieves Time limit: 1.0 secondMemory limit: 64 MB The Galaxy Police (Galaxpol) found ...
- HDU3491 Thieves(最小割)
题目大概说,一个国家有n个城市,由m条双向路相连,小偷们从城市s出发准备到h城市,警察准备在某些除了s和h外的城市布置警力抓小偷,各个城市各有警力所需的数目.问警察最少要布置多少警力才能万无一失地抓住 ...
- URAL 1277 Cops and Thieves
Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...
- hdu3870-Catch the Theves(平面图最小割)
Problem Description A group of thieves is approaching a museum in the country of zjsxzy,now they are ...
- hdu 3870(平面图最小割转最短路)
Catch the Theves Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65768/32768 K (Java/Others) ...
- BZOJ 1391: [Ceoi2008]order [最小割]
1391: [Ceoi2008]order Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1509 Solved: 460[Submit][Statu ...
- BZOJ-2127-happiness(最小割)
2127: happiness(题解) Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1806 Solved: 875 Description 高一 ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
随机推荐
- Python学习:变量
变量(Variables): 是为了存储程序在运算过程中的一些中间结果,为了方便日后调用储存在计算的内存中 官方介绍: Variables are used to storeinformation t ...
- (数据科学学习手札19)R中基本统计分析技巧总结
在获取数据,并且完成数据的清洗之后,首要的事就是对整个数据集进行探索性的研究,这个过程中会利用到各种描述性统计量和推断性统计量来初探变量间和变量内部的基本关系,本篇笔者便基于R,对一些常用的数据探索方 ...
- ccpc 2018 final G - Pastoral Life in Stardew Valley
#include <iostream> #include<cstdio> #include<cstring> #include<queue> using ...
- SIMD数据并行(一)——向量体系结构
在计算机体系中,数据并行有两种实现路径:MIMD(Multiple Instruction Multiple Data,多指令流多数据流)和SIMD(Single Instruction Multip ...
- 笔记-python-动态添加属性
笔记-python-动态添加属性 1. 添加对象/类属性 添加对象属性 class Person(object): def __init__(self, newName, newAge): ...
- asp.net MVC+easyUI 文件上传
前言:公司前端都是index页面引用js,剩下的添加...都是html页.加大操作难度5555,所以就是主页面操作子页面上传.效果如下: 1,前端html页代码如下 .其中请注意,form中encty ...
- error LNK2001: unresolved external symbol "public: __thiscall ControllerInterface::ControllerInterface(class QObject *)" (??0ControllerInterface@@QAE@PAVQObject@@@Z) downloadcontroller.obj
前几天刚遇到这个问题,但是今天再碰到就又要思考怎么解决.这次特别记录一下,以防下次碰到再手足无措: 1.看到这个报错第一感觉LNK关键字,表示连接错误,这种错误有几个可以下手的点 1)函数声明和定义是 ...
- Google序列化库FlatBuffers 1.1发布,及与protobuf的比较
个人总结: FlatBuffer相对于Protobuffer来讲,优势如下: 1. 由于省去了编解码的过程,所以从速度上快于Protobuffer,个人测试结果100w次编解码,编码上FlatBuff ...
- 第二篇 Python初识别及变量名定义规范
第一个Python程序 可以打开notepad或者其他文本编辑器,输入:print("Hello Python!"),将文件保存到任意盘符下,后缀名是 .py 两种python程 ...
- nginx启动和配置
1.命令行参数 -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的.路径应为绝对路径 -t 不运行,而仅仅测试配置文件.nginx 将检查配置文件的语 ...