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. Java学习笔记四:Java的八种基本数据类型

    Java的八种基本数据类型 Java语言提供了八种基本类型.六种数字类型(四个整数型,两个浮点型),一种字符类型,还有一种布尔型. Java基本类型共有八种,基本类型可以分为三类,字符类型char,布 ...

  2. Tensorflow 笔记:第一讲

    一. 基本概念 1. 什么是人工智能 人工智能的概念: 机器模拟人的意识和思维 重要人物: 艾伦·麦席森·图灵( Alan Mathison Turing) 人物简介: 1912 年 6 月 23 日 ...

  3. Linux编程之Epoll高并发

    网络上所有资料都说epoll是高并发.单线程.IO重叠服用的首选架构,比select和poll性能都要好,特别是在有大量不活跃连接的情况下.具体原理就不阐述了,下面说说使用. 具有有三个函数: #in ...

  4. (数据科学学习手札08)系统聚类法的Python源码实现(与Python,R自带方法进行比较)

    聚类分析是数据挖掘方法中应用非常广泛的一项,而聚类分析根据其大体方法的不同又分为系统聚类和快速聚类,其中系统聚类的优点是可以很直观的得到聚类数不同时具体类中包括了哪些样本,而Python和R中都有直接 ...

  5. (长期更新)OI常用模板

    代码很简单的模板就不收录了. DFT 离散傅立叶变换 void dft(pdd *a,int l,bool r){ int i,j=l/2,k; for(i=1;i<l;++i){ if(i&l ...

  6. Ubuntu server中 samba的安装和简单配置

    samba是Linux系统上的一种文件共享协议,可以实现Windows系统访问Linux系统上的共享资源,现在介绍一下如何在Ubuntu 14.04上安装和配置samba 工具/原料   Ubuntu ...

  7. python中判断输入是否为数字(包括浮点数)

    1.当num确定为数字后 num=123.4print(isinstance(num,float))#判断是否为浮点数 print(isinstance(num,int))#判断是否为整数 2.当nu ...

  8. 【个人训练】The Cow Lexicon(POJ-3267)

    继续大战dp.2018年11月30日修订,更新一下现在看到这个题目的理解(ps:就现在,poj又503了). 题意分析 这条题目的大意是这样的,问一字符串内最少删去多少的字符使其由给定的若干字符串构成 ...

  9. 13.0 Excel表格写入

    Excel表格写入 安装 xlutils 和 xlwt Excel写入输入 分两种方式: 第一种是向一张新表之中写入..这种不多说,我几乎没怎么用,直接贴代码 import xlwt Excel_na ...

  10. Leetcode 680.验证回文字符串

    验证回文字符串 给定一个非空字符串 s,最多删除一个字符.判断是否能成为回文字符串. 示例 1: 输入: "aba" 输出: True 示例 2: 输入: "abca&q ...