luogu P3576 [POI2014]MRO-Ant colony
一群蚂蚁能被吃,也就是走到指定边的两端点之一要走到另一端点时有\(k\)只,我们可以从这两端点逆推,记两个值为走到某个点时最后会被吃掉\(k\)只蚂蚁的蚂蚁数量范围,式子下面有,很好理解(雾).最后在每个叶子节点二分查找有多少个数在区间内即可
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define LL long long
#define il inline
#define re register
#define inf 2099999999
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define db double
#define eps (1e-5)
using namespace std;
const int N=1000000+10;
il LL rd()
{
re LL x=0,w=1;re char ch=0;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
LL d[N];
int to[N<<1],nt[N<<1],hd[N],tot=1;
il void add(int x,int y)
{
++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot,++d[x];
++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot,++d[y];
}
int n,g,k,ma,xx,yy;
LL ll[N],rr[N],ans,a[N];
void dfs(int x,int ffa)
{
for(int i=hd[x];i;i=nt[i])
{
int y=to[i];
if(y==ffa) continue;
ll[y]=min(ll[x]*max(d[x]-1,1ll),a[g]+10),rr[y]=min((rr[x]+1)*max(d[x]-1,1ll)-1,a[g]+10);
dfs(y,x);
}
if(d[x]==1)
{
int l=0,r=g,z=g,zz=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid]<ll[x]) z=mid,l=mid+1;
else r=mid-1;
}
l=0,r=g;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid]<=rr[x]) zz=mid,l=mid+1;
else r=mid-1;
}
ans+=max(zz-z,0);
}
}
int main()
{
n=rd(),g=rd(),k=rd();
for(int i=1;i<=g;i++) a[i]=rd();
sort(a+1,a+g+1);
a[0]=-1;
add(xx=rd(),yy=rd());
for(int i=2;i<n;i++) add(rd(),rd());
ll[xx]=rr[xx]=k,dfs(xx,yy);
ll[yy]=rr[yy]=k,dfs(yy,xx);
printf("%lld\n",ans*k);
return 0;
}
luogu P3576 [POI2014]MRO-Ant colony的更多相关文章
- 洛谷——P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- 洛谷 P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- [BZOJ3872][Poi2014]Ant colony
[BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...
- bzoj 3872: [Poi2014]Ant colony -- 树形dp+二分
3872: [Poi2014]Ant colony Time Limit: 30 Sec Memory Limit: 128 MB Description There is an entranc ...
- 【BZOJ3872】[Poi2014]Ant colony 树形DP+二分
[BZOJ3872][Poi2014]Ant colony Description 给定一棵有n个节点的树.在每个叶子节点,有g群蚂蚁要从外面进来,其中第i群有m[i]只蚂蚁.这些蚂蚁会相继进入树中, ...
- Codeforces 474 F. Ant colony
线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #271 (Div. 2) F. Ant colony 线段树
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【BZOJ3872】Ant colony(二分,动态规划)
[BZOJ3872]Ant colony(二分,动态规划) 题面 又是权限题... Description There is an entrance to the ant hill in every ...
- CodeForces 474F Ant colony ST+二分
Ant colony 题解: 因为一个数是合法数,那么询问区间内的其他数都要是这个数的倍数,也就是这个区间内的gcd刚好是这个数. 对于这个区间的gcd来说,不能通过前后缀来算. 所以通过ST表来询问 ...
随机推荐
- arctan
ArcTanWhen the ArcTan functional configuration is selected, the input vector (X_IN,Y_IN) is rotated( ...
- 洛谷 P3657 [USACO17FEB]Why Did the Cow Cross the Road II P
题面 大意:让你把两个n的排列做匹配,连线不想交,而且匹配的数字的差<=4,求最大匹配数 sol:(参考了kczno1的题解)对于第一个排列从左往右枚举,用树状数组维护到达另一个序列第i个数字的 ...
- BZOJ3110[Zjoi2013]K大数查询——权值线段树套线段树
题目描述 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数是 ...
- BZOJ4455 ZJOI2016小星星(容斥原理+树形dp)
相当于给树上的每个点分配一个编号使父亲和儿子间都有连边. 于是可以考虑树形dp:设f[i][j][k]为i号点的编号为j,其子树中编号集合为k的方案数.转移显然.然而复杂度3n·n3左右,具体我也不知 ...
- Harmonic Number LightOJ - 1234 (分段打表)
题意: 求调和级数,但n很大啦.. 解析: 分段打表 每间隔50存储一个数,在计算时 只需要找到离输入的n最近的那个数 以它为起点 开始计算即可 emm...补充一下调和级数的运算公式 r为常 ...
- day10 函数的嵌套执行顺序
函数嵌套的执行顺序,从上往下,一层一层的执行重点注意的是函数和内存的交互原理 NMAE = def yangtuo(): # 2 将整个函数放入内存编译,但是不执行 name = "yang ...
- 搬进Github
学习参考 萌码 一.Github简介和基本操作 Github 上操作基本上围绕一个个项目展开.项目就是一个文件夹,在github中成为“仓库”(repository),里面放着所有的项目文件,可以是代 ...
- [luogu1912][bzoj4196][NOI2015]软件管理器
题解 树剖模板题,每次改变是\(1\)或者是\(0\),区间求和和区间修改就可了. ac代码 # include <cstdio> # include <cstring> # ...
- Helm使用详解
使用1.helm search 查看charts stable是官方的 local是自己的 2.查看repo helm repo list 3.安装 helm install stable/mysql ...
- Spring Boot Actuator的端点
Spring Boot Actuator的关键特性是在应用程序里提供众多Web端点,通过它们了解应用程序 运行时的内部状况.有了Actuator,你可以知道Bean在Spring应用程序上下文里是如何 ...