【Ural1277】 Cops and Thieves 无向图点连通度问题
2017-05-16 14:38
369 查看
1277. Cops and ThievesTime limit: 1.0 secondMemory limit: 64 MB 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. InputThe 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: N, M, S 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). OutputWrite “YES” if it is possible to block all the possible routes within given limitations, and “NO” otherwise.Samples
|
题解:
每一个点拆成两个点并建边(i,i+n,Ri),保证每个点只被经过一次。
然后就是把每一条边(i,j)拆成(i+n,j,INF)和(j+n,i,INF);
然后最小割就是最少人数 与k对比即可。
注意特判S,T在同一点时的情况。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N=305,INF=1999999999; int gi(){ int str=0;char ch=getchar(); while(ch>'9'||ch<'0')ch=getchar(); while(ch>='0' && ch<='9')str=str*10+ch-'0',ch=getchar(); return str; } int head ,q ,dep ,num=1,S,T; struct Lin{ int next,to,dis; }a[N*N]; void init(int x,int y,int z){ a[++num].next=head[x]; a[num].to=y; a[num].dis=z; head[x]=num; a[++num].next=head[y]; a[num].to=x; a[num].dis=0; head[y]=num; } bool bfs() { memset(dep,0,sizeof(dep)); int x,u,t=0,sum=1;dep[S]=1;q[1]=S; while(t!=sum) { x=q[++t]; for(int i=head[x];i;i=a[i].next){ u=a[i].to; if(a[i].dis<=0 || dep[u])continue; dep[u]=dep[x]+1;q[++sum]=u; } } return dep[T]; } int dfs(int x,int flow) { if(x==T || !flow)return flow; int u,sum=0,tmp; for(int i=head[x];i;i=a[i].next){ u=a[i].to; if(dep[u]!=dep[x]+1 || a[i].dis<=0)continue; tmp=dfs(u,min(flow,a[i].dis)); a[i].dis-=tmp;a[i^1].dis+=tmp; sum+=tmp;flow-=tmp; if(!flow)break; } return sum; } int maxflow(){ int tmp,tot=0; while(bfs()){ tmp=dfs(S,INF); while(tmp)tot+=tmp,tmp=dfs(S,INF); } return tot; } int main() { int k=gi(),x,y; int n=gi(),m=gi();S=gi();T=gi(); if(S==T){ printf("NO\n"); return 0; } S+=n; for(int i=1;i<=n;i++){ x=gi(); init(i,i+n,x); } for(int i=1;i<=m;i++){ x=gi();y=gi(); init(x+n,y,INF);init(y+n,x,INF); } int pd=maxflow(); if(pd<=k)printf("YES"); else printf("NO"); return 0; }
相关文章推荐
- Ural 1277 - Cops and Thieves 无向图的最小点割
- ural 1277. Cops and Thieves【最小割】
- URAL 1277 Cops and Thieves 最小割
- Ural 1277 Cops and Thieves(最小点割集/最小割)
- URAL 1277 Cops and Thieves 最小割 无向图点带权点连通度
- URAL 1277 Cops and Thieves
- ural 1277. Cops and Thieves【最小割】
- URAL 1277 Cops and Thieves
- 1277. Cops and Thieves
- UVAL1277_Cops and Thieves
- uva 1277 Cops and Thieves(完成阻击所需要的最少人数)
- There is no Action mapped for namespace / and action name ..问题分析
- 解决no volume control Gstreamer plugins and/or devices found 问题
- URAL 1026. Questions and answers
- 二级域名共享Cookie时碰到的问题:Padding is invalid and cannot be removed
- 用 MapFileAndCheckSum 函数检测 exe 或 dll 是否被修改 - 回复 "Joe Lo" 的问题
- snmp 中的MIB变量ifInOctets and ifOutOctets 溢出问题
- arcsde9.2中text的存储类型问题(unicode,varchar and nvarchar)
- 使用JBOSS IDE的xdoclet来generate struts and spring xdoclet的问题
- 2个问题 Array and SQL