ZOJ3229:Shoot the Bullet 有源汇上下界最大流
来源:互联网 发布:java 引号转义 编辑:程序博客网 时间:2024/05/17 04:44
ccc写完没法submit什么鬼,相信自己,应该写对了,如果挂了不要打我。
Part3:
有源汇上下界最大流。
。。其实我的直观想法是二分然后跑可行流?不过我们不用这样。
因为跑可行流是恰好满足下界,这时候超级源点到超级汇点虽然已经无法继续流了,但是源点到汇点可能还可以继续流,那么我们再做一遍源点到汇点的最大流就行啦。
至于这题的建图非常显然就不说了,懒癌晚期
#include<iostream>#include<cstring>#include<cstdio>#define inf 1000000007#define N 1505#define M 100005using namespace std;int n,m,cnt,total,edge,S,T,SS,TT;int head[N],cur[N],dis[N],q[N],du[N],day[N],down[N];int next[M],list[M],key[M];inline int read(){ int a=0,f=1; char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();} return a*f;}inline void insert(int x,int y,int z){ next[++cnt]=head[x]; head[x]=cnt; list[cnt]=y; key[cnt]=z;}inline bool BFS(int S,int T){ int t=0,w=1,x; memset(dis,-1,sizeof(dis)); q[1]=S; dis[S]=1; while (t<w) { x=q[++t]; for (int i=head[x];i;i=next[i]) if (key[i]&&dis[list[i]]==-1) dis[q[++w]=list[i]]=dis[x]+1; } return dis[T]!=-1;}int find(int x,int flow,int T){ if (x==T) return flow; int w,used=0; for (int i=cur[x];i;i=next[i]) if (key[i]&&dis[list[i]]==dis[x]+1) { w=find(list[i],min(key[i],flow-used),T); key[i]-=w; key[i^1]+=w; used+=w; if (key[i]) cur[x]=i; if (used==flow) return used; } if (!used) dis[x]=-1; return used;}inline int dinic(int S,int T){ int ans=0; while (BFS(S,T)) { for (int i=0;i<=T;i++) cur[i]=head[i]; ans+=find(S,inf,T); } return ans;}int main(){ while (scanf("%d%d",&n,&m)!=EOF) { S=0; T=n+m+1; SS=T+1; TT=T+2; cnt=1; total=0; edge=0; memset(head,0,sizeof(head)); memset(du,0,sizeof(du)); for (int i=1;i<=m;i++) { int x=read(); du[T]+=x; du[i+n]-=x; } for (int i=1;i<=n;i++) { int C=read(); day[i]=read(); while (C--) { int x=read(),l=read(),r=read(); insert(i,n+x+1,r-l),insert(n+x+1,i,0); du[i]-=l; du[n+x+1]+=l; down[++edge]=l; } } for (int i=1;i<=n;i++) insert(S,i,day[i]),insert(i,S,0); for (int i=1;i<=m;i++) insert(i+n,T,inf),insert(T,i+n,0); insert(T,S,inf); insert(S,T,0); for (int i=0;i<=n+m+1;i++) if (du[i]>0) total+=du[i],insert(SS,i,du[i]),insert(i,SS,0); else if (du[i]<0) insert(i,TT,-du[i]),insert(TT,i,0); if (dinic(SS,TT)!=total) puts("-1"); else { printf("%d\n",dinic(S,T)); for (int i=1;i<=edge;i++) printf("%d\n",down[i]+key[i<<1|1]); } puts(""); } return 0;}
0 0
- 【ZOJ3229】Shoot the Bullet 有源汇上下界最大流
- ZOJ3229:Shoot the Bullet 有源汇上下界最大流
- 【有源汇上下界最大流】ZOJ3229[Shoot the Bullet]题解
- 【有源汇点上下界最大流】[ZOJ3229]Shoot the Bullet
- 【网络流】 ZOJ 3229 Shoot the Bullet 有源汇上下界最大流
- ZOJ 3229Shoot the Bullet 有源汇上下界网络流 最大流
- ZOJ 3229 Shoot the Bullet 有源汇上下界最大流
- zoj 3229 Shoot the Bullet(有源汇上下界最大流)
- 【有源汇上下界最大流】ZOJ 3229 Shoot the Bullet
- 【有源汇上下界最大流】ZOJ 3229 Shoot the Bullet
- 有源汇上下界最大流 ZOJ 3229 Shoot the Bullet
- zoj3229 有源汇上下界最大流
- 【有源汇有上下界最大流】ZOJ-3229 Shoot the Bullet
- ZOJ - 3229 Shoot the Bullet(有源有汇上下界最大流)
- zoj 3229 Shoot the Bullet--有源汇 有上下界 最大流 递归和非递归sap
- 【ZOJ】3229 Shoot the Bullet 上下界最大流
- ZOJ3229 Shoot the Bullet
- ZOJ 3229 Shoot the Bullet(有源汇有上下界的最大流)
- Android NDK环境配置
- 链接字符串各属性介绍
- Apache Felix Event Admin在ServiceMix容器下使用
- leetcode--Linked List Cycle II
- 构建微服务-第一章-什么是微服务_008总结
- ZOJ3229:Shoot the Bullet 有源汇上下界最大流
- Log4j 配置详解
- three.js制作一个立体几何体
- Windows10下搭建React Native Android开发环境
- android inflater 用法
- Snackbar的使用
- 仿微信引导界面PageAdapter
- #Android学习#RecyclerView基础
- Spring AOP拦截对Controller的请求时的配置失败