1277. Cops and Thieves

Time limit: 1.0 second
Memory limit: 64 MB
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 (x1, …, xN) separated with white-space character — the number of policemen required to control each of the stations (∑i=1Nxi ≤ 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.

Samples

input output
10
5 5 1 5
1 6 6 11 1
1 2
1 3
2 4
3 4
4 5
NO
10
5 5 1 5
1 4 4 11 1
1 2
1 3
2 4
3 4
4 5
YES

题意大概是:封锁每一个点需要一个最少人数Ri,选择封锁几个点使得S,T的所有道路都被封锁.判断封锁需要的人数是否满足<=k

题解:

每一个点拆成两个点并建边(i,i+n,Ri),保证每个点只被经过一次。

然后就是把每一条边(i,j)拆成(i+n,j,INF)和(j+n,i,INF);

然后最小割就是最少人数 与k对比即可。

注意特判S,T在同一点时的情况。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,INF=;
int gi(){
int str=;char ch=getchar();
while(ch>''||ch<'')ch=getchar();
while(ch>='' && ch<='')str=str*+ch-'',ch=getchar();
return str;
}
int head[N],q[N],dep[N],num=,S,T;
struct Lin{
int next,to,dis;
}a[N*N];
void init(int x,int y,int z){
a[++num].next=head[x];
a[num].to=y;
a[num].dis=z;
head[x]=num;
a[++num].next=head[y];
a[num].to=x;
a[num].dis=;
head[y]=num;
}
bool bfs()
{
memset(dep,,sizeof(dep));
int x,u,t=,sum=;dep[S]=;q[]=S;
while(t!=sum)
{
x=q[++t];
for(int i=head[x];i;i=a[i].next){
u=a[i].to;
if(a[i].dis<= || dep[u])continue;
dep[u]=dep[x]+;q[++sum]=u;
}
}
return dep[T];
}
int dfs(int x,int flow)
{
if(x==T || !flow)return flow;
int u,sum=,tmp;
for(int i=head[x];i;i=a[i].next){
u=a[i].to;
if(dep[u]!=dep[x]+ || a[i].dis<=)continue;
tmp=dfs(u,min(flow,a[i].dis));
a[i].dis-=tmp;a[i^].dis+=tmp;
sum+=tmp;flow-=tmp;
if(!flow)break;
}
return sum;
}
int maxflow(){
int tmp,tot=;
while(bfs()){
tmp=dfs(S,INF);
while(tmp)tot+=tmp,tmp=dfs(S,INF);
}
return tot;
}
int main()
{
int k=gi(),x,y;
int n=gi(),m=gi();S=gi();T=gi();
if(S==T){
printf("NO\n");
return ;
}
S+=n;
for(int i=;i<=n;i++){
x=gi();
init(i,i+n,x);
}
for(int i=;i<=m;i++){
x=gi();y=gi();
init(x+n,y,INF);init(y+n,x,INF);
}
int pd=maxflow();
if(pd<=k)printf("YES");
else printf("NO");
return ;
}

【Ural1277】 Cops and Thieves 无向图点连通度问题的更多相关文章

  1. URAL1277 Cops and Thieves(最小割)

    Cops and Thieves Description: The Galaxy Police (Galaxpol) found out that a notorious gang of thieve ...

  2. URAL 1277 - Cops and Thieves - [无向图点带权的最小点割]

    题目链接:https://cn.vjudge.net/problem/URAL-1277 The Galaxy Police (Galaxpol) found out that a notorious ...

  3. URAL 1277 Cops and Thieves

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

  4. POJ 1966 Cable TV Network (无向图点连通度)

    [题意]给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. [思路]回想一下s->t的最小点割,就是去掉多少个点能使得s.t不连通.那么求点连通度就枚举 ...

  5. POJ 1966 求无向图点连通度

    思路: n^2枚举(必须要n^2枚举啊)+拆点 特此嘲讽网上诸多垃圾题解,你们许多都是错的 -yyh //By SiriusRen #include <queue> #include &l ...

  6. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  7. POJ 1966

    求的是无向图的点连通度.开始便想到网络流,既然选的是点,当然就要拆点加边了.但无论如何也不敢往枚举源汇点的方向想,因为网络流复习度很高.看看网上大牛的,都是枚举,再看数据,原来N才50个点,枚举无压力 ...

  8. UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)

    题意:给一个无向图,求其点连通度?(注意输入问题) 思路: 如果只有1个点,那么输出“1”: 如果有0条边,那么输出“0”: 其他情况:用最大流解决.下面讲如何建图: 图的连通度问题是指:在图中删去部 ...

  9. UVA1660 Cable TV Network (无向图的点连通度)

    题意:求一个无向图的点连通度. 把一个点拆成一个入点和一个出点,之间连一条容量为1的有向边,表示能被用一次.最大流求最小割即可. 一些细节的东西:1.源点固定,汇点要枚举一遍,因为最小割割断以后会形成 ...

随机推荐

  1. Bate版敏捷冲刺报告--day0

    1 团队介绍 团队组成: PM:齐爽爽(258) 小组成员:马帅(248),何健(267),蔡凯峰(285)  Git链接:https://github.com/WHUSE2017/C-team 2 ...

  2. 20162328蔡文琛week07

    学号 2016-2017-2 <程序设计与数据结构>第X周学习总结 教材学习内容总结 多态引用在不同的时候可以指向不同类型的对象. 多态引用在运行时才将方法调用用于它的定义绑定在一起. 引 ...

  3. bisect 二分查找

    先说明的是,使用这个模块的函数前先确保操作的列表是已排序的. 先看看 insort  函数: 其插入的结果是不会影响原有的排序. 再看看 bisect  函数: 其目的在于查找该数值将会插入的位置并返 ...

  4. Flask 应用最佳实践

    一个好的应用目录结构可以方便代码的管理和维护,一个好的应用管理维护方式也可以强化程序的可扩展性 应用目录结构 假定我们的应用主目录是"flask-demo",首先我们建议每个应用都 ...

  5. DOM相关知识

    一.查找元素 间接查找 parentNode // 父节点 childNodes // 所有子节点 firstChild // 第一个子节点 lastChild // 最后一个子节点 nextSibl ...

  6. Environment.getExternalStorageDirectory()

    Environment.getExternalStorageDirectory()得到的是storage/emulated/0

  7. 使用ArrayList时代码内部发生了什么(jdk1.7)?

    前言 ArrayList(这里的ArrayList是基于jdk1.7)是在项目中经常使用的集合类,例如我们从数据库中查询出一组数据.这篇文章不去剖析它的继承和实现,只是让我们知道实例化及增删改查时它的 ...

  8. node防xss攻击插件

    var xss = require('node-xss').clean; router.post("/orders/insert-orders", function (req, r ...

  9. WPF 自定义RadioButton样式

    一.RadioButton基本样式 RadioButton基本样式包含两种状态,这里也是使用两张图片来代替两种状态,当然你也可以通过IconFont或Path来替换这两种状态. 效果如下: 样式代码如 ...

  10. Python模块 - os , sys.shutil

    os 模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录: ...