【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 [模型] 有源汇点的上下界最小流.即既满足上下界又满足 ...
随机推荐
- 病毒(bzoj 2938)
Description 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码 ...
- 34深入理解C指针之---通过字符串传递函数
一.通过字符串传递函数 1.定义:可以使用函数名(字符串)调用函数,也可以使用函数指针调用函数,将两者结合 2.特征: 1).在函数声明时使用函数指针 2).调用函数时使用函数名称(字符串) 3).可 ...
- hdu 4506(数学,循环节+快速幂)
小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- LeetCode OJ--Next Permutation *
求一个排列的下一个排列. 1,2,3 → 1,3,23,2,1 → 1,2,31,1,5 → 1,5,1 #include <iostream> #include <vector&g ...
- 匿名块的四个类型(type rowtype record table)
Oracle PL/SQL块 匿名块的四个类型 type rowtype record table ---- type (列类型) %type类型是指声明变量的时候,参考某个表的某个列的类型---- ...
- 期望DP初步
感觉期望DP这种东西像是玄学- 主要总结说一点基础性的东西, 或许对于理解题目的做法会有一点帮助. 首先是关于独立事件, 互斥事件的概念. 通俗地说, 就是对于两个事件A, B, 假如满足发生了其中一 ...
- Kermit,Xmodem,1K-Xmodem,Ymodem,Zmodem传输协议小结
来自:http://blog.163.com/czblaze_3333/blog/static/208996228201272295236713/ Kermit协议 报文格式: 1. MA ...
- python 依照list中的dic的某key排序
面试题之中的一个. s=[ {"name":"Axx","score":"90"}, {"name" ...
- awk中的NR FNR
shell编程中,awk简直就是一把利器,你能够把它看成shell的一部分,也能够看成一种单独的语言,功能十分强大.今天先来说一说NR与FNR 先准备两个文件: 1.txt,内容为: user pas ...
- hql 时间
1.hql中时间格式转换 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d ...