【BZOJ2625】[Neerc2009]Inspection 最小流
【BZOJ2625】[Neerc2009]Inspection
Description
Your team has to inspect each slope of the ski resort. Ski lifts on this resort are not open yet, but you have a helicopter. In one fiight the helicopter can drop one person into any point of the resort. From the drop off point the person can ski down the slopes, inspecting each slope as they ski. It is fine to inspect the same slope multiple times, but you have to minimize the usage of the helicopter. So, you have to figure out how to inspect all the slopes with the fewest number of helicopter flights.
Input
Output
Sample Input
1 3
1 7
2 4 5
1 8
1 8
0
2 6 5
0
Sample Output
题解:经典的最小链覆盖问题。
采用有上下界的网络流的思路,将每个点拆成两个,从出点向入点连一条(0,inf)的边,对于每条边(a,b)从a的出点向b的入点连一条(1,inf)的边。然后先跑可行流再反着跑最大流。但是发现一个性质,第一遍跑可行流时一定能够满流,所以我们直接跑第二遍即可,具体连边方法:
1.S->每个点的出点,每个点的入点->T 容量inf
2.每个点的入点->出点 容量inf
3.对于(a,b),a的出点->b的入点 容量inf,a的出点->S,b的入点->T 容量1
ans=m-从T到S的最大流
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int inf=1<<30;
int n,m,S,T,cnt,ans;
int to[100000],next[100000],val[100000],head[1000],d[1000],m1[1000],m2[1000];
queue<int> q;
int rd()
{int ret=0,f=1; char gc=getchar();while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();return ret*f;
}
void add(int a,int b,int c,int d)
{to[cnt]=b,val[cnt]=c,next[cnt]=head[a],head[a]=cnt++;to[cnt]=a,val[cnt]=d,next[cnt]=head[b],head[b]=cnt++;
}
int dfs(int x,int mf)
{if(x==T) return mf;int i,k,temp=mf;for(i=head[x];i!=-1;i=next[i]){if(d[to[i]]==d[x]+1&&val[i]){k=dfs(to[i],min(temp,val[i]));if(!k) d[to[i]]=0;val[i]-=k,val[i^1]+=k,temp-=k;if(!temp) break;}}return mf-temp;
}
int bfs()
{while(!q.empty()) q.pop();memset(d,0,sizeof(d));int i,u;q.push(S),d[S]=1;while(!q.empty()){u=q.front(),q.pop();for(i=head[u];i!=-1;i=next[i]){if(!d[to[i]]&&val[i]){d[to[i]]=d[u]+1;if(to[i]==T) return 1;q.push(to[i]);}}}return 0;
}
int main()
{n=rd(),S=0,T=2*n+1;int i,a,b;memset(head,-1,sizeof(head));for(i=1;i<=n;i++){a=rd(),m1[i]=a,ans+=a;while(a--) b=rd(),add(i,b+n,inf,0),m2[b]++;}for(i=1;i<=n;i++) add(S,i,inf,m1[i]),add(i+n,T,inf,m2[i]),add(i+n,i,inf,0);swap(S,T);while(bfs()) ans-=dfs(S,inf);printf("%d",ans);return 0;
}
转载于:https://www.cnblogs.com/CQzhangyu/p/7297651.html
【BZOJ2625】[Neerc2009]Inspection 最小流相关推荐
- 有上下界网络流 ---- P4843 清理雪道(DAG图上最小路径重复边覆盖)【模板】有源汇上下界最小流
题目链接 题目大意: 解题思路: 首先我们发现对于每条边至少要覆盖一次,最多覆盖无数次 那么就有点像上下界网络流了[1,INF][1,INF][1,INF]的限制关系 跑一边最小流就可以了!! #in ...
- HDU 3157 Crazy Circuits(有源汇上下界最小流)
HDU 3157 Crazy Circuits 题目链接 题意:一个电路板,上面有N个接线柱(标号1~N),还有两个电源接线柱 + -.给出一些线路,每一个线路有一个下限值求一个能够让全部部件正常工作 ...
- SGU-176 Flow construction 有上下界的最小流
这里参看了大牛的解题思路,学习了很多.原来上下界流的求法是这么的灵活,尤其我是用的临界表存储的边,删除更新很不方便. http://www.shuizilong.com/house/archives/ ...
- BZOJ 2502: 清理雪道 [最小流]
2502: 清理雪道 题意:任意点出发任意次每条边至少经过一次最小花费. 下界1,裸最小流.... #include <iostream> #include <cstdio> ...
- 【有源汇点上下界最小流】[SGU176]Flow construction
题目大意 给出N个点,M条有向边 如果有向边的标号是1的话,就表示该边的上界下界都为容量 如果有向边的标号为0的哈,表示该边的下界为0,上界为容量 现在问,从1到N的最小流是多少,并输出每条边的流量 ...
- [BZOJ2502]清理雪道解题报告|带下界的最小流
滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定时清理雪道.你们拥有一架直升飞机,每次飞 ...
- LOJ - #117. 有源汇有上下界最小流(有源汇有上下界的最小流)
题目链接:点击查看 题目大意:给出一个 n 个点和 m 条边的有向图,每条边都有一个流量限制 [ lower , upper ],给定源点 s 和汇点 t ,求出源点到汇点的最小流 题目分析:参考我的 ...
- POJ 3801/HDU 3157 Crazy Circuits | 有下界的最小流
题目: POJ最近总是炸 所以还是用HDU吧http://acm.hdu.edu.cn/showproblem.php?pid=3157 题解: 题很长,但其实就是给个有源汇带下界网络流(+是源,-是 ...
- 图论:有源汇有上下界最小流
这次就是最小流了 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll I ...
最新文章
- 手把手教你写一个生成对抗网络
- oracle导出超过100m的数据库,Oracle数据库的导出和导入
- 使用librosa计算pcen
- 自学python需要买书吗-Python真的适合每个人学习吗 学习Python需要多久
- 数组去重(JavaScript)先从网上整理一波,待验证
- 移动端真机测试怎么做
- 沈阳java基础培训,辽宁沈阳java培训学费大概多少
- popwindow+动画
- 目标规划第四章计算机求解,单纯形算法与目标规划地应用研究.doc
- 基于java在线问卷调查系统
- 海思Hi3559A Sample_comm_vdec模块解码 视频解码解析
- DTCloud编码规范
- 四六级、考研英语单词记忆---知米背单词APP推荐!
- vue 动态 Prop
- c语言中的百分数怎么求,如何计算具体百分比
- 奇奇怪怪的大佬:从职业赌徒到互联网大佬
- 组建项目团队-执行过程组
- 什么是欧拉角/姿态角?
- Did you install mysqlclient?
- 微信视频号怎么变现挣钱?六大变现操作方式。