URAL 1277 Cops and Thieves
Cops and Thieves
This problem will be judged on Ural. Original ID: 1277
64-bit integer IO format: %lld Java class name: (Any)
Input
Output
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的更多相关文章
- URAL 1277 - Cops and Thieves - [无向图点带权的最小点割]
题目链接:https://cn.vjudge.net/problem/URAL-1277 The Galaxy Police (Galaxpol) found out that a notorious ...
- 【Ural1277】 Cops and Thieves 无向图点连通度问题
1277. Cops and Thieves Time limit: 1.0 secondMemory limit: 64 MB The Galaxy Police (Galaxpol) found ...
- URAL1277 Cops and Thieves(最小割)
Cops and Thieves Description: The Galaxy Police (Galaxpol) found out that a notorious gang of thieve ...
- URAL 1877 Bicycle Codes
1877. Bicycle Codes Time limit: 0.5 secondMemory limit: 64 MB Den has two four-digit combination loc ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
随机推荐
- CGI和Servlet的比较
转载自:http://www.maxhis.info/java/cgi-vs-servlet/ 概括来说,CGI和Servlet可以完成相同的功能. CGI(Common Gateway Interf ...
- Hadoop工作流--ChainMapper/ChainReducer?(三)
不多说,直接上干货! Hadoop的ChainMapper和ChainReducer使用案例(链式处理) 什么是ChainMapper/ChainReducer?
- 降低winnt Apache服务的权限,让你的虚拟主机更安全
winnt 安装 Apache 后,在后台的服务默认是以system权限运行的(system是winnt的最高权限),这给服务器带来很大的安全隐患,最近我遇到的就是php的W8C 文件管理既然可以随意 ...
- android开发学习 ------- json数据与实体类之间的相互转换
在网络请求的时候,会返回给我们实体类,我们需要将实体类转化为json字符串,方便处理数据: 有时候也会将json数据转换为实体类. 在Android Studio中,json要互相转换,需要用到gso ...
- lock和synchronized的同步区别与选择
1. lock是一个接口,而synchronized是java的一个关键字,synchronized是内置的语言实现:(具体实现上的区别在<Java虚拟机>中有讲解底层的CAS不同,以前有 ...
- jsapi4加载的首个图层的范围被默认作为地图范围,且不能修改的解决
在map加载的第一个图层的图层范围(fullExtent),会被默认设置为map的全图范围,且不能更改,从一般地图控件角度来说,应该有fullExtent属性,作为地图的全图范围,但很遗憾jsapi4 ...
- checkbox设置复选框的只读效果不让用户勾选
在Web开发中,有时候需要显示一些复选框(checkbox),表明这个地方是可以进行勾选操作的,但是有时候是只想告知用户"这个地方是可以进行勾选操作的"而不想让用户在此处勾选(比如 ...
- LibreOJ #109. 并查集
题目描述 这是一道模板题. 维护一个 nnn 点的无向图,支持: 加入一条连接 uuu 和 vvv 的无向边 查询 uuu 和 vvv 的连通性 由于本题数据较大,因此输出的时候采用特殊的输出方式:用 ...
- python实现: protobuf解释器
之前项目为了自动化,所以写一个protobuf的解释器,用来生成项目所需的格式. 当然现在通过以下链接的指导,跳过手工分析,直接生成代码了. https://developers.google.com ...
- pylint安装失败的解决方法
原文链接http://www.cnblogs.com/Loonger/p/7815335.html 使用命令pip3 install pylint安装pylint是出现错误.查了一圈也找不到答案.仔细 ...