题面

既然我们只知道最后数量为$k$的蚂蚁会在特殊边上被吃掉,不妨逆着推回去,然后到达每个叶节点的时候就会有一个被吃掉的蚂蚁的区间,然后二分一下就好啦

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,maxx=1e9;
int ant[N],deg[N],leaf[N];
int p[N],noww[*N],goal[*N];
int n,g,k,t,root,t1,t2,n1,n2,cnt;
long long ans;
void link(int f,int t)
{
noww[++cnt]=p[f];
goal[cnt]=t,p[f]=cnt;
}
void DFS(int nde,int fth,long long l,long long r)
{
if(l>maxx) return ; if(r>maxx) r=maxx;
for(int i=p[nde];i;i=noww[i])
if(goal[i]!=fth)
t=deg[goal[i]]-,DFS(goal[i],nde,l*t,r*t+t-);
if(leaf[nde])
ans+=(upper_bound(ant+,ant++g,r)-lower_bound(ant+,ant++g,l))*k;
}
int main ()
{
scanf("%d%d%d",&n,&g,&k);
for(int i=;i<=g;i++)
scanf("%d",&ant[i]);
sort(ant+,ant++g);
scanf("%d%d",&n1,&n2);
link(n1,n2),link(n2,n1);
deg[n1]++,deg[n2]++;
for(int i=;i<n;i++)
{
scanf("%d%d",&t1,&t2);
link(t1,t2),link(t2,t1);
deg[t1]++,deg[t2]++;
}
for(int i=;i<=n;i++) if(deg[i]==) deg[i]=,leaf[i]=true;
root=n1,DFS(n1,n2,k*(deg[n1]-),k*(deg[n1]-)+deg[n1]-);
root=n2,DFS(n2,n1,k*(deg[n2]-),k*(deg[n2]-)+deg[n2]-);
printf("%lld",ans);
return ;
}

解题:POI 2014 Ant colony的更多相关文章

  1. bzoj 3872 [ Poi 2014 ] Ant colony —— 二分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3872 从食蚁兽所在的边向叶节点推,会得到一个渐渐放大的取值区间,在叶子节点上二分有几群蚂蚁符 ...

  2. [BZOJ3872][Poi2014]Ant colony

    [BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...

  3. Codeforces 474 F. Ant colony

    线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes inpu ...

  4. 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 ...

  5. 【BZOJ3872】Ant colony(二分,动态规划)

    [BZOJ3872]Ant colony(二分,动态规划) 题面 又是权限题... Description There is an entrance to the ant hill in every ...

  6. bzoj 3872: [Poi2014]Ant colony -- 树形dp+二分

    3872: [Poi2014]Ant colony Time Limit: 30 Sec  Memory Limit: 128 MB Description   There is an entranc ...

  7. 【BZOJ3872】[Poi2014]Ant colony 树形DP+二分

    [BZOJ3872][Poi2014]Ant colony Description 给定一棵有n个节点的树.在每个叶子节点,有g群蚂蚁要从外面进来,其中第i群有m[i]只蚂蚁.这些蚂蚁会相继进入树中, ...

  8. CodeForces 474F Ant colony ST+二分

    Ant colony 题解: 因为一个数是合法数,那么询问区间内的其他数都要是这个数的倍数,也就是这个区间内的gcd刚好是这个数. 对于这个区间的gcd来说,不能通过前后缀来算. 所以通过ST表来询问 ...

  9. Codeforces G. Ant colony

    题目描述: F. Ant colonytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputo ...

随机推荐

  1. 理解粒子滤波(particle filter)

    1)初始化阶段-提取跟踪目标特征 该阶段要人工指定跟踪目标,程序计算跟踪目标的特征,比如可以采用目标的颜色特征.具体到Rob Hess的代码,开始时需要人工用鼠标拖动出一个跟踪区域,然后程序自动计算该 ...

  2. Tree - AdaBoost with sklearn source code

    In the previous post we addressed some issue of decision tree, including instability, lack of smooth ...

  3. 工程能力之C4模型

    概述 刚在InfoQ上看到一篇介绍C4Model的文章,觉得这个模型设计的很赞,很有指导意义,做个简单的记录. Why,为什么需要架构图? ThoughtWorks中国 文章中有几句话我觉得很有道理, ...

  4. dvwa——命令注入&文件包含

    命令注入 commond_injection 源码.分析.payload: low: <?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input ...

  5. hive对于lzo文件处理异常Caused by: java.io.IOException: Compressed length 842086665 exceeds max block size 67108864 (probably corrupt file)

    hive查询lzo数据格式文件的表时,抛 Caused by: java.io.IOException: Compressed length 842086665 exceeds max block s ...

  6. Maven学习记录3——创建、编译、打包、运行项目

    http://blog.csdn.net/yaya1943/article/details/48464371

  7. java代码生成xml 报错:HIERARCHY_REQUEST_ERR: 尝试在不允许的位置插入节点。

    document.appendChild(controlElement)好像只能append一个根节点

  8. java第三次实验

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计   班级:1352       姓名:陈实  学号:20135224 成绩:             指导 ...

  9. Java第一次试验

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计   班级:1352       姓名:朱国庆   学号:20135237 成绩:             ...

  10. 20162314 《Program Design & Data Structures》Learning Summary Of The Seventh Week

    20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The Seventh Wee ...