URAL 1277 Cops and Thieves

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=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

Source

 
解题:很典型的最小割模型
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int INF = ~0U>>2;
 4 const int maxn = 300;
 5 struct arc {
 6     int to,flow,next;
 7     arc(int x = 0,int y = 0,int z = -1) {
 8         to = x;
 9         flow = y;
10         next = z;
11     }
12 } e[maxn*maxn];
13 int head[maxn],gap[maxn],d[maxn],tot,S,T,n,m;
14 void add(int u,int v,int flow){
15     e[tot] = arc(v,flow,head[u]);
16     head[u] = tot++;
17     e[tot] = arc(u,0,head[v]);
18     head[v] = tot++;
19 }
20 void bfs() {
21     queue<int>q;
22     q.push(T);
23     memset(d,-1,sizeof d);
24     memset(gap,0,sizeof gap);
25     d[T] = 0;
26     while(!q.empty()) {
27         int u = q.front();
28         q.pop();
29         ++gap[d[u]];
30         for(int i = head[u]; ~i; i = e[i].next) {
31             if(e[i^1].flow && d[e[i].to] == -1) {
32                 d[e[i].to] = d[u] + 1;
33                 q.push(e[i].to);
34             }
35         }
36     }
37 }
38 int sap(int u,int low) {
39     if(u == T) return low;
40     int tmp = 0,minh = 2*n - 1;
41     for(int i = head[u]; ~i; i = e[i].next) {
42         if(e[i].flow) {
43             if(d[u] == d[e[i].to] + 1) {
44                 int a = sap(e[i].to,min(e[i].flow,low));
45                 e[i].flow -= a;
46                 e[i^1].flow += a;
47                 tmp += a;
48                 low -= a;
49                 if(!low) break;
50                 if(d[S] >= 2*n) return tmp;
51             }
52             if(e[i].flow)  minh = min(minh,d[e[i].to]);
53         }
54     }
55     if(!tmp){
56         if(--gap[d[u]] == 0) d[S] = 2*n;
57         ++gap[d[u] = minh + 1];
58     }
59     return tmp;
60 }
61 int maxflow(int ret = 0){
62     bfs();
63     while(d[S] < 2*n) ret += sap(S,INF);
64     return ret;
65 }
66 int main() {
67     int police,u,v;
68     while(~scanf("%d",&police)){
69         scanf("%d%d%d%d",&n,&m,&S,&T);
70         S = n + S;
71         memset(head,-1,sizeof head);
72         tot = 0;
73         for(int i = 1,tmp; i <= n; ++i){
74             scanf("%d",&tmp);
75             add(i,n + i,tmp);
76         }
77         for(int i = 0; i < m; ++i){
78             scanf("%d%d",&u,&v);
79             add(u + n,v,INF);
80             add(v + n,u,INF);
81         }
82         puts(((S - n == T)||(maxflow() > police))?"NO":"YES");
83     }
84     return 0;
85 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4928805.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值