URAL1277 Cops and Thieves(最小割)

URAL1277 Cops and Thieves(最小割),第1张

概述Cops and Thieves Description: 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

cops and ThIEves

Description:

The galaxy Police (galaxpol) found out that a notor@R_404_6928@s 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 (  x  1,…,  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:
105 5 1 51 6 6 11 11 21 32 43 44 5
Sample Output:
NO
题意: 给出一个无向图以及其起点和终点,每个点都有点权,问是否能用k个人去截断起点到终点的路径,注意不能将人员安排在起点和终点上面。   题解: 就是一个最小割的问题,建双向边以及拆点就好了。因为不能在起点和终点安排人员,所以起点和终点拆边的时候容量为无穷大就行了。   代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <queue>#define INF 1e9using namespace std;typedef long long ll;const int N = 505,M = 1e5+5;int n,m,s,F,tot,k;int w[N],head[N],d[N];struct Edge{    int u,v,c,next;}e[M];voID adde(int u,int v,int c){    e[tot].v=v;e[tot].next=head[u];e[tot].c=c;head[u]=tot++;    e[tot].v=u;e[tot].next=head[v];e[tot].c=0;head[v]=tot++;}int bfs(){    memset(d,0,sizeof(d));d[F]=1;    queue <int > q;q.push(F);    while(!q.empty()){        int u=q.front();q.pop();        for(int i=head[u];i!=-1;i=e[i].next){            int v=e[i].v;            if(e[i].c>0 && !d[v]){                d[v]=d[u]+1;                q.push(v);            }        }    }    return d[s+n]!=0;}int dfs(int S,int a){    if(S==s+n || a==0) return a;    int flow=0,f;    for(int i=head[S];i!=-1;i=e[i].next){        int v=e[i].v;        if(d[v]!=d[S]+1) continue ;        f=dfs(v,min(a,e[i].c));        if(f>0){            e[i].c-=f;            e[i^1].c+=f;            flow+=f;            a-=f;            if(a==0) break;        }    }    if(!flow) d[S]=-1;    return flow;}int Dinic(int S,int T){    int flow = 0;    while(bfs())        flow+=dfs(S,INF);    return flow ;}int main(){    cin>>k>>n>>m>>s>>F;    memset(head,-1,sizeof(head));    for(int i=1;i<=n;i++) scanf("%d",&w[i]);    for(int i=1;i<=n;i++){        if(i==s ||i==F) adde(i,i+n,INF);        else adde(i,w[i]);    }    for(int i=1;i<=m;i++){        int u,v;        scanf("%d%d",&u,&v);        adde(u+n,INF);adde(v+n,u,INF);    }    int flow = Dinic(F,s+n);    if(flow>k) cout<<"NO";    else cout<<"YES";    return 0;}
@H_501_502@ 总结

以上是内存溢出为你收集整理的URAL1277 Cops and Thieves(最小割)全部内容,希望文章能够帮你解决URAL1277 Cops and Thieves(最小割)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1234528.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存