博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AC日记——[NOI2006]最大获利 bzoj 1497
阅读量:4472 次
发布时间:2019-06-08

本文共 1719 字,大约阅读时间需要 5 分钟。

 

思路:

  最小割;

 

来,上代码:

#include 
#include
#include
#include
using namespace std;#define maxn 55005#define maxm 1005005#define INF 0x7fffffffint deep[maxn],que[maxm],F[maxm],cnt=1;int n,m,s,t=maxn-1,head[maxn],E[maxm],V[maxm];inline void in(int &now){ char Cget=getchar();now=0; while(Cget>'9'||Cget<'0') Cget=getchar(); while(Cget>='0'&&Cget<='9') { now=now*10+Cget-'0'; Cget=getchar(); }}inline void edge_add(int u,int v,int f){ E[++cnt]=head[u],V[cnt]=v,F[cnt]=f,head[u]=cnt; E[++cnt]=head[v],V[cnt]=u,F[cnt]=0,head[v]=cnt;}inline bool bfs(){ memset(deep,-1,sizeof(deep)); int h=0,tail=1;que[0]=s,deep[s]=0; while(h
0&&deep[V[i]]<0) { deep[V[i]]=deep[now]+1; if(V[i]==t) return true; que[tail++]=V[i]; } } } return false;}int flowing(int now,int flow){ if(now==t||flow<=0) return flow; int oldflow=0; for(int i=head[now];i;i=E[i]) { if(F[i]>0&&deep[V[i]]==deep[now]+1) { int pos=flowing(V[i],min(flow,F[i])); flow-=pos,oldflow+=pos; F[i]-=pos,F[i^1]+=pos; if(flow==0) return oldflow; } } if(oldflow==0) deep[now]=-1; return oldflow;}int main(){ in(n),in(m);int pos,u,v,sum=0; for(int i=1;i<=n;i++) in(pos),edge_add(s,i,pos); for(int i=1;i<=m;i++) { in(u),in(v),in(pos); sum+=pos; edge_add(u,i+n,INF); edge_add(v,i+n,INF); edge_add(i+n,t,pos); } pos=0;while(bfs()) pos+=flowing(s,INF); cout<

 

转载于:https://www.cnblogs.com/IUUUUUUUskyyy/p/6741707.html

你可能感兴趣的文章
网站架构模式(二)
查看>>
【数据结构】算法 LinkList (Add Two Numbers)
查看>>
Bugtags:移动时代首选 Bug 管理系统
查看>>
hibernate学习笔记之一 hibernate简介
查看>>
定时任务quartz
查看>>
Set集合和实现类
查看>>
Ubuntu 12.04安装vim和配置
查看>>
centos配置jdk
查看>>
我在清华当工程师的日子
查看>>
mysql基础
查看>>
编程如写作
查看>>
sql server 事务和锁的作用
查看>>
Nginx安装配置
查看>>
DFS ACM Battle(巧妙爆搜)
查看>>
WebService小白学习 之 使用jdk实现暴露接口 (1)
查看>>
uva 1633 Dyslexic Gollum
查看>>
性能优化方法学
查看>>
卡片翻转效果
查看>>
Shell脚本中使用test测试命令测试数值
查看>>
cookie和session
查看>>