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. Andrew Ng Machine Learning Coursera学习笔记

    课程记录笔记如下: 1.目前ML的应用 包括:数据挖掘database mining.邮件过滤email anti-spam.机器人autonomous robotics.计算生物学computati ...

  2. 数据库中pymysql模块的使用

    pymysql 模块 使用步骤: 核心类Connect链接用和Cursor读写用 1. 与数据库服务器建立链接 2. 获取游标对象(用于发送和接收数据) 3. 用游标执行sql语句 4. 使用fetc ...

  3. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  4. Spyder在windows下常用快捷键

    块注释/反块注释:Ctrl+4/5 行注释/反行注释:Ctrl+1 代码提示:Tab 复制一行:Ctrl+Alt+↓/↑ 删除一行:Ctrl+D 运行:F5 全屏:F11 撤销:Ctrl+Z 反撤销: ...

  5. Java——static关键字---18.09.27

    static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但在Java语言中没有全局变量的概念. static关键字主要有两种作用: 一.为某特定数据类 ...

  6. linux进程 生产者消费者

    #include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<string.h> # ...

  7. What to do when Enterprise Manager is not able to connect to the database instance (ORA-28001)

    摘自:http://dbtricks.com/?p=34 If you are trying to connect to the Oracle enterprise Manger and you ge ...

  8. [网站日志]今天早上遭遇的CPU 100%情况

    今天早上9:06左右,Windows性能监视器监测到主站的Web服务器出现了CPU 100%的情况,伴随着Requests/Sec的上升,详见下图. 上图中红色线条表示的是%Processor Tim ...

  9. python,批量生成指定格式的审核数据(传输参数格式为数组时)

    #思路#获取list长度(例如列表有20条数据,则生成20条数据),生成数组长度为list元素的数据,完成对列表20条数据的批量审核def createBatchData(self,str_in,li ...

  10. 第二十四篇configparser(**)

    configparser模块 config:配置,parser:解析.字面意思理解configparser模块就是配置文件的解析模块. 来看一个好多软件的常见文档格式如下: [DEFAULT] # 标 ...