URAL1277Cops and Thieves Dinic最大流
2015-08-23 22:22
309 查看
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 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: 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).
Output
Write “YES” if it is possible to block all the possible routes within given limitations, and “NO” otherwise.
Sample Input
首先弄明白题意要干嘛……在一个无向图中小偷要偷东西..小偷从s点出发..要偷的东在点e...警察可以用一些警力封锁一些点让小偷无论如何都不能到达e 求最小割
第一行的数字K,表示一共有这么多的警察,即最后的最大流不能超过这个数字。N星球个数,即点的个数。M:边的个数(最最原始,每两个点连着的边的个数)S: 起点 F:终点 下行每个点:每个星球所需警察数 再下面:连着的点对
如何建模是重点!据说最小割都是这么建模的,把一个点拆成两个 原来点上的权变成拆成两点间流的大小。最小割啊最小割~这么一说就明白了是不是~
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: 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).
Output
Write “YES” if it is possible to block all the possible routes within given limitations, and “NO” otherwise.
Sample Input
input | output |
---|---|
10 5 5 1 5 1 6 6 11 1 1 2 1 3 2 4 3 4 4 5 | NO |
10 5 5 1 5 1 4 4 11 1 1 2 1 3 2 4 3 4 4 5 | YES |
第一行的数字K,表示一共有这么多的警察,即最后的最大流不能超过这个数字。N星球个数,即点的个数。M:边的个数(最最原始,每两个点连着的边的个数)S: 起点 F:终点 下行每个点:每个星球所需警察数 再下面:连着的点对
如何建模是重点!据说最小割都是这么建模的,把一个点拆成两个 原来点上的权变成拆成两点间流的大小。最小割啊最小割~这么一说就明白了是不是~
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int inf=0x3f3f3f3f; const int maxn=100000; const int maxe=1000000; int sum,s,e,head[maxn],level[maxn],que[maxn],n,m; struct node{ int w,to,next; }edge[maxe]; inline void add(int u,int v,int c) { edge[sum].to=v; edge[sum].w=c; edge[sum].next=head[u]; head[u]=sum++; edge[sum].to=u; edge[sum].w=0; edge[sum].next=head[v]; head[v]=sum++; } inline bool bfs() { memset(level,0,sizeof(level)); int p=0; que[p++]=s; level[s]=1; for(int i=0;i<p;i++) { int temp=que[i]; for(int k=head[temp];k>-1;k=edge[k].next) if(edge[k].w && (!level[edge[k].to])){ que[p++]=edge[k].to; level[edge[k].to]=level[temp]+1; } } return level[e]; } int dfs(int now,int maxf) { if(now==e)return maxf; int ret=0; for(int i=head[now];i>-1 && ret<maxf; i=edge[i].next) if(edge[i].w && (level[edge[i].to]==level[now]+1)) { int temp=dfs(edge[i].to,min(maxf-ret,edge[i].w)); edge[i].w-=temp; edge[i^1].w+=temp; ret+=temp; } if(ret==0)level[now]=0; return ret; } inline int dinic() { int ans=0; while(bfs())ans+=dfs(s,inf); return ans; } int main() { //freopen("cin.txt","r",stdin); int k,w,a,b; while(~scanf("%d",&k)) { sum=0; memset(head,-1,sizeof(head)); scanf("%d%d%d%d",&n,&m,&s,&e); s=s<<1|1; e=e<<1; for(int i=1;i<=n;i++) { scanf("%d",&w); add(i<<1,i<<1|1,w); add(i<<1|1,i<<1,w); } for(int i=0;i<m;i++) { scanf("%d%d",&a,&b); add(a<<1|1,b<<1,inf); add(b<<1|1,a<<1,inf); } if(dinic()<=k && s!=e+1 && s!=e-1 && s!=e) puts("YES"); else puts("NO"); } return 0; }
相关文章推荐
- Tomcat与Web应用的配置
- Linux命令:ls命令使用方法
- Linux下简单Shell实现(二)基本功能---主函数及init()函数
- tomcat_server.xml配置说明
- 一个网站有很大的访问量,有什么办法来解决?
- linux延时函数
- Tomcat的配置文件 —— server.xml
- linux修改环境变量
- centos6.5 postgresql-9.4下数据库的迁移
- linux内核编译
- linux驱动程序 硬件访问
- 从虚拟机启动移动硬盘的linux
- linux驱动概述
- Linux下批量转换到utf-8编码的问题
- oracle linux和centos 7.1安装docker的两种方法
- linux内核中的IS_ERR()、PTR_ERR()、ERR_PTR()
- 坚持不懈之linux haproxy的配置文件关键字查询手册
- Linux并发控制方式
- nginx的安装
- Visual Studio 2010 error C2065: '_In_opt_z_' : undeclared identifier 编译错误