【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;
}
【BZOJ2625】[Neerc2009]Inspection 最小流的更多相关文章
- 【bzoj2625】[Neerc2009]Inspection 有上下界最小流
题目描述 You are in charge of a team that inspects a new ski resort. A ski resort is situated on several ...
- UVaLive 4597 Inspection (网络流,最小流)
题意:给出一张有向图,每次你可以从图中的任意一点出发,经过若干条边后停止,然后问你最少走几次可以将图中的每条边都走过至少一次,并且要输出方案,这个转化为网络流的话,就相当于 求一个最小流,并且存在下界 ...
- UVa 1440:Inspection(带下界的最小流)***
https://vjudge.net/problem/UVA-1440 题意:给出一个图,要求每条边都必须至少走一次,问最少需要一笔画多少次. 思路:看了好久才勉强看懂模板.良心推荐:学习地址. 看完 ...
- 【BZOJ-2502】清理雪道 有上下界的网络流(有下界的最小流)
2502: 清理雪道 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 594 Solved: 318[Submit][Status][Discuss] ...
- 【BZOJ-2893】征服王 最大费用最大流(带下界最小流)
2893: 征服王 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 156 Solved: 48[Submit][Status][Discuss] D ...
- HDU3157 Crazy Circuits(有源汇流量有上下界网络的最小流)
题目大概给一个电路,电路上有n+2个结点,其中有两个分别是电源和负载,结点们由m个单向的部件相连,每个部件都有最少需要的电流,求使整个电路运转需要的最少电流. 容量网络的构建很容易,建好后就是一个有源 ...
- POJ 3801 有上下界最小流
1: /** 2: POJ 3801 有上下界的最小流 3: 4: 1.对supersrc到supersink 求一次最大流,记为f1.(在有源汇的情况下,先使整个网络趋向必须边尽量满足的情况) 5: ...
- bzoj 2502 清理雪道(有源汇的上下界最小流)
[题意] 有一个DAG,要求每条边必须经过一次,求最少经过次数. [思路] 有上下界的最小流. 边的下界为1,上界为无穷.构造可行流模型,先不加ts边跑一遍最大流,然后加上t->s的inf边跑 ...
- sgu 176 Flow construction(有源汇的上下界最小流)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11025 [模型] 有源汇点的上下界最小流.即既满足上下界又满足 ...
随机推荐
- P1473 校门外的树3
时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 校门外有很多树,有苹果树,香蕉树,有会扔石头的,有可以吃掉补充体力的……如今学校决定在某个时刻在某一段种上一 ...
- AForge.NET 设置摄像头分辨率
AForge.NET 老版本在预览摄像头时可通过设置DesiredFrameSize 属性,设置摄像头支持的分辨率,新版本提示已过期: 解决办法: 获取VideoCapabilities属性集合,选中 ...
- PHP使用JpGraph绘制折线图
PHP使用JpGraph绘制折线图 下载jpgraph类库,使用的是src目录下的类文件. require_once './src/jpgraph.php'; require_once './src/ ...
- iOS上实现圆角图片
UIImageView自带 //圆角设置 imageView.layer.cornerRadius = ;(值越大,角就越圆) imageView.layer.masksToBounds = YES; ...
- yii使用bootstrap分页样式
Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.Bootstra ...
- 首次远程安装 GlassFish 后以远程 Web 方式访问其后台管理系统出现错误的解决方法(修订)
首次远程安装 GlassFish 服务后,如果以远程 Web 方式访问其后台管理系统,会提示 Secure Admin must be enabled to access the DAS remote ...
- Pollard_rho定理 大数的因数个数 这个板子超级快
https://nanti.jisuanke.com/t/A1413 AC代码 #include <cstdio> #include <cstring> #include &l ...
- Spring Boot + Elastic stack 记录日志
原文链接:https://piotrminkowski.wordpress.com/2019/05/07/logging-with-spring-boot-and-elastic-stack/ 作者: ...
- cmake使用(CMakeList.txt)
set(CMAKE_INCLUDE_CURRENT_DIR ON)#CMAKE_INCLUDE_CURRENT_DIR equal to INCLUDE_DIRECTORY(${CMAKE_CURRE ...
- nginx--cookies转发
nginx根据cookie分流 nginx根据cookie分流众所周知,nginx可以根据url path进行分流,殊不知对于cookie分流也很强大,同时这也是我上篇提到的小流量实验的基础. 二 ...