Description

给你一棵树,现在要建立一些消防站,有以下要求: 1. 消防站要建立在节点上,每个节点可能建立不只一个消防站。 2. 每个节点应该被一个消防站管理,这个消防站不一定建立在该节点上。 3. 每个消防站可以管理至多s个节点。 4. 消防站只能管理距离(两点间最短路径的边数)不超过k的结点。请问至少要设立多少个消防站。

Input

第一行n,s,k。接下来n-1行每行xi,yi描述一条边连接xi与yi。 1<=n<=100000 1<=s<=n 1<=k<=20 1<=xi

Output

一个数,最少的消防站个数。

Sample Input

12 3 1

1 12

3 8

7 8

8 9

2 12

10 12

9 12

4 8

5 8

8 11

6 8

Sample Output

4

HINT


这题容易想到一个贪心策略,消防站必定先控制距离为k的点,然后距离递减,但是这个东西我们不好维护,所以我们就可以维护两个数组,用这两个数组来互相抵消维护。

转移的时候有一句话需要注意:

for (int i=k;i;i--)     more[x][i-1]+=more[son][i];

为什么是i来更新i-1,因为我控制的点有两个方向,一边向儿子,一边向父亲,向父亲方向的点显然要这么更新;由于儿子方向的点被两个数组互相抵消了两个距离的节点,所以这样更新是没有问题的

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=1e5,M=20;
int pre[(N<<1)+10],now[N+10],child[(N<<1)+10],tot;
ll more[N+10][M+10],need[N+10][M+10];
int n,m,k,Ans;
void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
void dfs(int x,int fa){
need[x][0]=1;
for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
if (son==fa) continue;
dfs(son,x);
for (int i=0;i<k;i++) need[x][i+1]+=need[son][i];
for (int i=k;i;i--) more[x][i-1]+=more[son][i];
}
int T=(need[x][k]+m-1)/m;
Ans+=T;
more[x][k]+=1ll*T*m;
for (int i=0;i<=k;i++){
if (more[x][i]){
for (int j=i;~i&&(j>=i-1||x==1);j--){//抵消掉两个距离的节点
if (more[x][i]<=need[x][j]){
need[x][j]-=more[x][i];
more[x][i]=0;
break;
}
more[x][i]-=need[x][j];
need[x][j]=0;
}
}
}
}
int main(){
n=read(),m=read(),k=read();
for (int i=1;i<n;i++){
int x=read(),y=read();
join(x,y),join(y,x);
}
dfs(1,0);
int tot=0;
for (int i=0;i<=k;i++) tot+=need[1][i];
Ans+=(tot+m-1)/m;
printf("%d\n",Ans);
return 0;
}

[POI2009]救火站Gas的更多相关文章

  1. BZOJ1117 [POI2009]救火站Gas 贪心

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ1117.html 题目传送门 - BZOJ1117 题意 给你一棵树,现在要建立一些消防站,有以下要求: ...

  2. [BZOJ1117]救火站gas

    Description 给你一棵树,现在要建立一些消防站,有以下要求: 1. 消防站要建立在节点上,每个节点可能建立不只一个消防站. 2. 每个节点应该被一个消防站管理,这个消防站不一定建立在该节点上 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. NOIP树上问题总结

    这几年考了好几次树上问题: NOIP2012 疫情控制(二分答案+倍增+贪心) NOIP2013 货车运输(最大生成树+倍增) NOIP2014 联合权值(勉强算作树形dp的傻逼题) NOIP2015 ...

  5. 【自编教材】16万8千字的HTML+CSS基础 适合从0到1-可收藏

    [图片链接有点小问题,这几天更新,敬请期待!] 目 录 第一章HTML基础 1.1 HTML简介和发展史 1.1.1 什么是HTML 1.1.2 HTML的发展历程 1.1.3 web标准 1.2 开 ...

  6. [Leetcode] gas station 气站

    There are N gas stations along a circular route, where the amount of gas at station i isgas[i]. You ...

  7. 20. Candy && Gas Station

    Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  8. Gas Station

    Description: There are N gas stations along a circular route, where the amount of gas at station i i ...

  9. bzoj 1133: [POI2009]Kon dp

    1133: [POI2009]Kon Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 242  Solved: 81[Submit][Status][D ...

随机推荐

  1. zedboard硬件连接过程

    1.      ZedBoard – Connect a 2nd micro-USBcable between the host machine and connector J17 (JTAG) 2. ...

  2. Prime Distance(二次筛素数)

    Description The branch of mathematics called number theory is about properties of numbers. One of th ...

  3. 使用VLC搭建视频直播服务器

    去年我们信息之夜我们进行过视频直播服务,当时我们使用了WMS(Windows Media Server)实现了这个服务,但是编码是微软的WMV,因而像iPhone/Android这样的智能手机无法观看 ...

  4. REST技术第四步 多个參数注解问题

    经过实验,发如今使用@BeanParam注解的查询类字段上. @FormParam和@QueryParam不能同一时候加上去,仅仅能加一个,否则会出现取不到数据的情况. 并且在方法參数上两个注解也不能 ...

  5. poj 1840 哈希

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14093   Accepted: 6927 Description ...

  6. dm385的分辨率切换

    建议用两个RSZ的输出来完成切换分辨率功能,帧率可以通过软件丢帧来实现. 两个SWMS增加了两个1080p60的读和写,对系统影响是比较大的. http://www.deyisupport.com/q ...

  7. (八)unity4.6Ugui中文教程文档-------概要-UGUI Rich Text

    大家好,我是孙广东. 转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:mod=guide&view ...

  8. 变量的命名和if语句

    1. 计算机是什么 基本组成: cpu: 主频, 核数(16) 内存:大小(8G, 16G, 32G) 型号: DDR3, DDR4, DDR5,  主频(海盗船,玩家国度) 显卡: 显存.型号(N- ...

  9. Hibernate 之 Locking

    在我们业务实现的过程中,往往会有这样的需求:保证数据访问的排他性,也就是我正在访问的数据,别人不能够访问,或者不能对我的数据进行操作.面对这样的需求,就需要通过一种机制来保证这些数据在一定的操作过程中 ...

  10. spring的PROPAGATION_REQUIRES_NEW事务,下列说法正确的是(D)

    A:内部事务回滚会导致外部事务回滚 B:内部事务回滚了,外部事务仍可以提交 C:外部事务回滚了,内部事务也跟着回滚 D:外部事务回滚了,内部事务仍可以提交 PROPAGATION_REQUIRES_N ...