Cops and Thieves

Time Limit: 1000ms
Memory Limit: 16384KB

This problem will be judged on Ural. Original ID: 1277
64-bit integer IO format: %lld      Java class name: (Any)

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.
 

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

Source

 
解题:很典型的最小割模型
 #include <bits/stdc++.h>
using namespace std;
const int INF = ~0U>>;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
} e[maxn*maxn];
int head[maxn],gap[maxn],d[maxn],tot,S,T,n,m;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
void bfs() {
queue<int>q;
q.push(T);
memset(d,-,sizeof d);
memset(gap,,sizeof gap);
d[T] = ;
while(!q.empty()) {
int u = q.front();
q.pop();
++gap[d[u]];
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i^].flow && d[e[i].to] == -) {
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
}
int sap(int u,int low) {
if(u == T) return low;
int tmp = ,minh = *n - ;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow) {
if(d[u] == d[e[i].to] + ) {
int a = sap(e[i].to,min(e[i].flow,low));
e[i].flow -= a;
e[i^].flow += a;
tmp += a;
low -= a;
if(!low) break;
if(d[S] >= *n) return tmp;
}
if(e[i].flow) minh = min(minh,d[e[i].to]);
}
}
if(!tmp){
if(--gap[d[u]] == ) d[S] = *n;
++gap[d[u] = minh + ];
}
return tmp;
}
int maxflow(int ret = ){
bfs();
while(d[S] < *n) ret += sap(S,INF);
return ret;
}
int main() {
int police,u,v;
while(~scanf("%d",&police)){
scanf("%d%d%d%d",&n,&m,&S,&T);
S = n + S;
memset(head,-,sizeof head);
tot = ;
for(int i = ,tmp; i <= n; ++i){
scanf("%d",&tmp);
add(i,n + i,tmp);
}
for(int i = ; i < m; ++i){
scanf("%d%d",&u,&v);
add(u + n,v,INF);
add(v + n,u,INF);
}
puts(((S - n == T)||(maxflow() > police))?"NO":"YES");
}
return ;
}

URAL 1277 Cops and Thieves的更多相关文章

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

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

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

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

  3. URAL1277 Cops and Thieves(最小割)

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

  4. URAL 1877 Bicycle Codes

    1877. Bicycle Codes Time limit: 0.5 secondMemory limit: 64 MB Den has two four-digit combination loc ...

  5. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  6. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  7. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  8. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  9. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

随机推荐

  1. CGI和Servlet的比较

    转载自:http://www.maxhis.info/java/cgi-vs-servlet/ 概括来说,CGI和Servlet可以完成相同的功能. CGI(Common Gateway Interf ...

  2. Hadoop工作流--ChainMapper/ChainReducer?(三)

    不多说,直接上干货! Hadoop的ChainMapper和ChainReducer使用案例(链式处理) 什么是ChainMapper/ChainReducer?

  3. 降低winnt Apache服务的权限,让你的虚拟主机更安全

    winnt 安装 Apache 后,在后台的服务默认是以system权限运行的(system是winnt的最高权限),这给服务器带来很大的安全隐患,最近我遇到的就是php的W8C 文件管理既然可以随意 ...

  4. android开发学习 ------- json数据与实体类之间的相互转换

    在网络请求的时候,会返回给我们实体类,我们需要将实体类转化为json字符串,方便处理数据: 有时候也会将json数据转换为实体类. 在Android Studio中,json要互相转换,需要用到gso ...

  5. lock和synchronized的同步区别与选择

    1. lock是一个接口,而synchronized是java的一个关键字,synchronized是内置的语言实现:(具体实现上的区别在<Java虚拟机>中有讲解底层的CAS不同,以前有 ...

  6. jsapi4加载的首个图层的范围被默认作为地图范围,且不能修改的解决

    在map加载的第一个图层的图层范围(fullExtent),会被默认设置为map的全图范围,且不能更改,从一般地图控件角度来说,应该有fullExtent属性,作为地图的全图范围,但很遗憾jsapi4 ...

  7. checkbox设置复选框的只读效果不让用户勾选

    在Web开发中,有时候需要显示一些复选框(checkbox),表明这个地方是可以进行勾选操作的,但是有时候是只想告知用户"这个地方是可以进行勾选操作的"而不想让用户在此处勾选(比如 ...

  8. LibreOJ #109. 并查集

    题目描述 这是一道模板题. 维护一个 nnn 点的无向图,支持: 加入一条连接 uuu 和 vvv 的无向边 查询 uuu 和 vvv 的连通性 由于本题数据较大,因此输出的时候采用特殊的输出方式:用 ...

  9. python实现: protobuf解释器

    之前项目为了自动化,所以写一个protobuf的解释器,用来生成项目所需的格式. 当然现在通过以下链接的指导,跳过手工分析,直接生成代码了. https://developers.google.com ...

  10. pylint安装失败的解决方法

    原文链接http://www.cnblogs.com/Loonger/p/7815335.html 使用命令pip3 install pylint安装pylint是出现错误.查了一圈也找不到答案.仔细 ...