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. Mysql的查询语句(联合查询、连接查询、子查询等)

    Mysql的各个查询语句(联合查询.连接查询.子查询等) 一.联合查询 关键字:union 语法形式 select语句1 union[union选项] select 语句2 union[union选项 ...

  2. NYOJ #21 三个水杯(bfs)

    描述 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个为空杯子.三个水杯之间相互倒水,并且水杯没有标识,只能根据给出的水杯体积来计算.现在要求你写出一个程序,使其输出使初始状态到达目标 ...

  3. SPRING-BOOT系列之SpringBoot的诞生及其和微服务的关系

    转载自 : https://www.cnblogs.com/ityouknow/p/9034377.html 微服务架构 微服务的诞生并非偶然,它是在互联网高速发展,技术日新月异的变化以及传统架构无法 ...

  4. toLocaleSting()

    之前一直忽略了这一方法,直到前天的笔试题,两种方式实现如下功能... 1234567890→1,234,567,890 当时我的思路是这样的:1.字符串反转,插入逗号,再反转 2.求余数,将字符串一分 ...

  5. mysql数据误删除(drop)的恢复. (ext3grep, extundelete)

    drop table tbl_name 物理删除.没有备份,没有二进制日志 在系统删除文件并非在存储中抹去数据,而仅仅是标识对应的block块可以被重新的分配使用.所以数据的恢复还是有希望的.但是那些 ...

  6. 【学习笔记】深入理解js原型和闭包(6)——继承

    为何用“继承”为标题,而不用“原型链”? 原型链如果解释清楚了很容易理解,不会与常用的java/C#产生混淆.而“继承”确实常用面向对象语言中最基本的概念,但是java中的继承与javascript中 ...

  7. Azure ARMTemplate模板,VM扩展命令

    Azure ARM模板中,给虚拟机安装扩展脚本的命令 "resources": [ { "apiVersion": "[variables('apiV ...

  8. (转)关于IC设计的想法 Author :Fengzhepianzhou

    一.工具的使用 工欲善其事,必先利其器.我们做IC设计的需要掌握的工具:仿真(vcs.modelsim),综合工具(dc.QS.ISE),时序分析(pt.其他的).以及后端的一些工具,比如astro. ...

  9. iOS开发-Runtime详解

    iOS开发-Runtime详解 简介 Runtime 又叫运行时,是一套底层的 C 语言 API,其为 iOS 内部的核心之一,我们平时编写的 OC 代码,底层都是基于它来实现的.比如: [recei ...

  10. 工作中Docker使用命令笔记

    docker安装与启动 安装docker [root@localhost /]# yum -y install docker-io 更改配置文件 [root@localhost /]# vi /etc ...