luogu2756飞行员配对问题
来源:互联网 发布:mac系统软件下载 编辑:程序博客网 时间:2024/05/17 03:40
题目
https://www.luogu.org/problem/show?pid=2756
题解
水题最大流。
代码
//最大流#include <cstdio>#include <algorithm>#include <cstring>#define maxn 1000000#define inf 0x3f3f3f3fusing namespace std;int N, M, head[maxn], next[maxn], to[maxn], c[maxn], S, T, tot=1, d[maxn], num[maxn], last[maxn],Exit;void adde(int a, int b, int cc){to[++tot]=b;c[tot]=cc;next[tot]=head[a];head[a]=tot;}void adde2(int a, int b, int cc){adde(a,b,cc);adde(b,a,0);}int isap(int pos, int in){int flow=0, t;if(pos==T)return in;for(int &p=last[pos];p;p=next[p])if(c[p] and d[to[p]]+1==d[pos]){flow+= t=isap(to[p],min(in-flow,c[p]));c[p]-=t, c[p xor 1]+=t;if(Exit or in==flow)return flow;}Exit=--num[d[pos]]==1;++num[++d[pos]];last[pos]=head[pos];return flow;}void build(){int i, x, y;scanf("%d%d",&M,&N);S=N+1, T=S+1;for(i=1;i<=M;i++)adde2(S,i,1);for(i=M+1;i<=N;i++)adde2(i,T,1);for(scanf("%d%d",&x,&y);x!=-1;adde2(x,y,1),scanf("%d%d",&x,&y));}void show(){int i, p;for(i=1;i<=M;i++)for(p=head[i];p;p=next[p])if(c[p]==0 and to[p]!=S)printf("%d %d\n",i,to[p]);}int main(){int flow;build();for(flow=0;!Exit;flow+=isap(S,inf));if(flow==0)printf("No Solution!\n");else{printf("%d\n",flow);show();}return 0;}
0 0
- luogu2756飞行员配对问题
- 二分图匹配——Luogu2756 [网络流24题]飞行员配对方案问题
- 飞行员配对方案问题
- 飞行员配对方案问题
- 飞行员配对方案问题
- 飞行员配对方案问题
- 飞行员配对方案问题
- 飞行员配对方案问题
- swust1736: 飞行员配对方案问题
- PowerOJ1736: 飞行员配对方案问题
- 飞行员配对
- 网络流 ~~飞行员配对方案问题
- 网络流1飞行员配对方案问题
- [codevs 1232] 飞行员配对方案问题
- 【网络流】飞行员配对方案问题
- 飞行员配对方案问题(二分图)
- ssl 2601 飞行员配对方案问题
- 洛谷 P 2756 飞行员配对方案问题
- springmvc+jdbc+mysql+bootstrap整合,并将sql语句提取到xml中(附源码!!)
- python关于sort排序功能
- [Mac] 记录解决Homebrew-cask Issue #21913过程
- 173----全选 反选
- C++程序编译过程
- luogu2756飞行员配对问题
- PBC library 学习笔记(一)
- [BZOJ4355]Play with sequence 吉司机线段树
- 第一篇博客
- set容器_自定义数据类型排序(仿函数应用)_insert判断返回值(pair的使用)
- css限制显示字数,文字长度超出部分用省略号表示 只显示一行
- TCP:WireShark分析,序列号Seq和确认号Ack
- iOS学习笔记-019.UIScrollView的基本属性和用法
- angular2-英雄指南教程http请求