Cops and Thieves

Description:

The Galaxy Police (Galaxpol) found out that a notorious gang of thieves has plans for stealing an extremely valuable exhibit from the Earth Planetary Museum — an ancient microprocessor. The police chiefs decided to intercept the criminals on the way from their refuge to the museum. A problem arose while planning the police operation: would it be possible for the Galaxpol staff to control all the possible routes of the criminals?
The galaxy transport system is designed as follows. Each planet has a transport station that is connected to some of the other stations via two-way teleportation channels. Transport stations vary in their sizes, so different numbers of policemen may be required to take control over different stations. In order not to upset the operation, it was decided to leave the planets that are next to the museum or the refuge without any police control.
Help the Galaxpol to place their staff at the stations in order to block all possible routes of the thieves.
Input:
 
The first line of the input contains a single integer 0 < K ≤ 10000 — the number of policemen engaged to control the stations.
The second line has four integers: NMS and F delimited with white-space character.
N is the number of stations in the galaxy (the stations are numbered from 1 to N); 2 < N ≤ 100.
M is the number of teleportation channels; 1 < M ≤ 10000.
S is the number of the planet (and the station) where the museum is; 1 ≤ S ≤ N.
F is the number of the planet (and the station) where the thieves’ refuge is; 1 ≤ F ≤ N.
The next line contains N integers ( x 1, …, xN) separated with white-space character — the number of policemen required to control each of the stations (∑ i=1 N xi ≤ 10000).
Then M lines follow that describe the teleportation channels. Each of these lines contains a pair of space-delimited integers — the numbers of stations being connected by a channel. The channel system is designed so that it is possible to reach any station from any other one (probably it would require several channel transitions).
 
Output:
 
Write “YES” if it is possible to block all the possible routes within given limitations, and “NO” otherwise.
 
Sample Input:
10
5 5 1 5
1 6 6 11 1
1 2
1 3
2 4
3 4
4 5
Sample Output:
NO
题意:
给出一个无向图以及其起点和终点,每个点都有点权,问是否能用k个人去截断起点到终点的路径,注意不能将人员安排在起点和终点上面。
 
题解:
就是一个最小割的问题,建双向边以及拆点就好了。因为不能在起点和终点安排人员,所以起点和终点拆边的时候容量为无穷大就行了。
 
代码如下:
#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(最小割)的更多相关文章

  1. HDU3870-Caught these thieves(最小割-&gt;偶图-&gt;最短路问题)

    A group of thieves is approaching a museum in the country of zjsxzy,now they are in city A,and the m ...

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

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

  3. HDU3491 Thieves(最小割)

    题目大概说,一个国家有n个城市,由m条双向路相连,小偷们从城市s出发准备到h城市,警察准备在某些除了s和h外的城市布置警力抓小偷,各个城市各有警力所需的数目.问警察最少要布置多少警力才能万无一失地抓住 ...

  4. URAL 1277 Cops and Thieves

    Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...

  5. hdu3870-Catch the Theves(平面图最小割)

    Problem Description A group of thieves is approaching a museum in the country of zjsxzy,now they are ...

  6. hdu 3870(平面图最小割转最短路)

    Catch the Theves Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65768/32768 K (Java/Others) ...

  7. BZOJ 1391: [Ceoi2008]order [最小割]

    1391: [Ceoi2008]order Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1509  Solved: 460[Submit][Statu ...

  8. BZOJ-2127-happiness(最小割)

    2127: happiness(题解) Time Limit: 51 Sec  Memory Limit: 259 MBSubmit: 1806  Solved: 875 Description 高一 ...

  9. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

随机推荐

  1. 3D Food Printing【3D食物打印】

    3D Food Printing There's new frontier in 3D printing that's begining to come into focus: food. 3D打印的 ...

  2. 来自一个大三开学三周的huster的迷茫与失措

    大三开学考研保研的话题开始多了起来.自从前天去听了一回谢长生教授的实验室宣讲会,回来直到现在都好像心头上压了些东西,喘不过气来.本来我就少与外界接触,加之我自己一个人主动学习的积极性也很是缺乏,所以当 ...

  3. 计蒜客-----跳跃游戏(C语言)

    /********************************************************给定一个非负整数数组,假定你的初始位置为数组第一个下标.数组中的每个元素代表你在那个位 ...

  4. Python3 logging模块&ConfigParser模块

    ''' 博客园 Infi_chu ''' ''' logging模块 该模块是关于日志相关操作的模块 ''' import logging # logging.debug('debug') # log ...

  5. (数据科学学习手札32)Python中re模块的详细介绍

    一.简介 关于正则表达式,我在前一篇(数据科学学习手札31)中已经做了详细介绍,本篇将对Python中自带模块re的常用功能进行总结: re作为Python中专为正则表达式相关功能做出支持的模块,提供 ...

  6. css在线sprite

    大家知道网站图片多,浏览器下载多个图片要有多个请求.可是请求比较耗时,那怎么办呢? 对,方法就是css sprite. 今天我们来看看css在线sprite 百度搜索css-sprite 打开www. ...

  7. Mysql自学笔记

    SQL(strucut query language) DDL (数据库定义语言)DML (数据库操作语言)DCL (数据库的控制语言)DTL (数据库的高级语言)查看版本的函数select vers ...

  8. samba与apache配置使用

    samba与apache根目录 1.直接将apache用户作为samba用户 2.给apache用户赋宇网站根目录的acl rwx权限 #注意 第一次不要加默认的权限 setfacl -m u:apa ...

  9. 【数据结构】 Queue 的简单实现

    [数据结构] Queue 的简单实现 public class XQueue<T> { /// <summary> /// 第一个元素 /// </summary> ...

  10. 每天一个Linux命令(12):su命令

    su命令用于切换当前用户身份到其他用户身份,变更时须输入所要变更的用户帐号与密码. 语法: su(选项)(参数) 选项: -c<指令>或--command=<指令>:执行完指定 ...