hdu 4289 Control (最小割)
来源:互联网 发布:c语言循环经典编程题 编辑:程序博客网 时间:2024/05/16 00:28
题意:
给出一个图,盗贼在s点,警察在t点,给出在每个点设置捕获点需要的花费,现在问在让盗贼无法通过需要的最少花费。
题解:
最小割定理,拆点后,把点权变为边权,然后跑一边最大流,结果就是最小割的值。
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>#include<vector>#include<queue>#include<map>#include<set>#define B(x) (1<<(x))using namespace std;void cmax(int& a,int b){ if(b>a)a=b; }void cmin(int& a,int b){ if(b<a)a=b; }typedef long long ll;const int oo=0x3f3f3f3f;const ll OO=1LL<<61;const int MOD=1000007;const int maxn=10000;const int maxm=500000;struct EDGE{ int v,next,c,f;}E[maxm<<1];int head[maxn],tol;int gap[maxn],dep[maxn],pre[maxn],cur[maxn];void Init(){ memset(head,-1,sizeof head); tol=0;}void add_edge(int u,int v,int f,int rf=0){ E[tol].v=v; E[tol].c=f; E[tol].f=0; E[tol].next=head[u]; head[u]=tol++; E[tol].v=u; E[tol].c=rf; E[tol].f=0; E[tol].next=head[v]; head[v]=tol++;}int isap(int start,int end,int N){ memset(gap,0,sizeof gap); memset(dep,0,sizeof dep); memcpy(cur,head,sizeof head); int u=start; pre[u]=-1; gap[0]=N; int ans=0; while(dep[start]<N){ if(u==end){ int Min=oo; for(int i=pre[u];i!=-1;i=pre[E[i^1].v]) if(Min>E[i].c-E[i].f) Min=E[i].c-E[i].f; for(int i=pre[u];i!=-1;i=pre[E[i^1].v]){ E[i].f+=Min; E[i^1].f-=Min; } u=start; ans+=Min; continue; } bool flag=false; int v; for(int i=cur[u];i!=-1;i=E[i].next){ v=E[i].v; if(E[i].c-E[i].f&&dep[v]+1==dep[u]){ flag=true; cur[u]=pre[v]=i; break; } } if(flag){ u=v; continue; } int Min=N; for(int i=head[u];i!=-1;i=E[i].next) if(E[i].c-E[i].f&&dep[E[i].v]<Min){ Min=dep[E[i].v]; cur[u]=i; } gap[dep[u]]--; if(!gap[dep[u]])return ans; dep[u]=Min+1; gap[dep[u]]++; if(u!=start)u=E[pre[u]^1].v; } return ans;}int drink[maxn],food[maxn];char jud[maxn];int main(){ //freopen("E:\\read.txt","r",stdin); int n,m,S,D,cost,u,v; int s,t; while(scanf("%d %d",&n,&m)!=EOF){ Init(); s=2*n+1; t=s+1; scanf("%d %d",&S,&D); add_edge(s,S,oo); add_edge(D+n,t,oo); for(int i=1;i<=n;i++){ scanf("%d",&cost); add_edge(i,i+n,cost); add_edge(i+n,i,cost); } for(int i=1;i<=m;i++){ scanf("%d %d",&u,&v); add_edge(u+n,v,oo); add_edge(v+n,u,oo); } int ans=isap(s,t,t); printf("%d\n",ans); } return 0;}
0 0
- 【最小割】HDU 4289 Control
- hdu 4289 Control (最小割)
- HDU 4289 Control(最小割)
- hdu 4289 Control(图论-最小割)
- HDU 4289 Control(最小割)
- hdu 4289 Control 最小割 isap
- hdu 4289 Control (最小割 sap)
- HDU - 4289 Control (最小割 MCMF)
- hdu 4289 Control【最小割+拆点】
- HDU 4289--Control【最小割 && 拆点】
- 最大流最小割-HDU-4289-Control
- hdu 4289 Control (成都网络赛最小割)
- hdu 4289 Control 网络流,最小割,拆点
- HDU 4289 Control (网络流-最小割)
- HDU 4289 Control (最小割 拆点)
- HDU 4289 Control(最大流、最小割)
- HDU 4289 Control 最小割最大流 拆点
- HDU 4289 Control (最大流最小割)
- 20150322_栈
- B. Mr. Kitayuta's Colorful Graph (CF #286 (Div. 2) 并查集)
- 【JAVA学习】“-Xmx1024m -Xms1024m -Xmn512m -Xss256k”——Java运行参数(转)
- 跟网络状态相关的工具类NetUtils
- MATLAB中eig的作用
- hdu 4289 Control (最小割)
- IntelliJ genymotion plugin installation
- MKNetWorkKit 的实质和其优越性,真的是异步请求;不会阻挡自己的线程。自己写一个就会体会到;
- Android 点击EditText的时候弹出软键盘,点击EditText之外空白处软键盘消失
- iphone时间戳与时间之间的相互转换,随机数的使用总结
- ubuntu如何完全卸载和安装 Java及android环境?
- svn学习-----来自好友王阳网易博客
- 64位ORACLE客户端上plsql无法识别ORACLE_HOME解决方案
- 空间容量相关的工具类PathSpaceUtils