题面

既然我们只知道最后数量为$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. Netty源码分析第5章(ByteBuf)---->第9节: ByteBuf回收

    Netty源码分析第五章: ByteBuf 第九节: ByteBuf回收 之前的章节我们提到过, 堆外内存是不受jvm垃圾回收机制控制的, 所以我们分配一块堆外内存进行ByteBuf操作时, 使用完毕 ...

  2. 可道云kodexplorer搭建私有云后的配置优化

    一.上传下载速度优化首先明确可道云没有对上传下载做任何限制,速度快慢和网络环境有关.可道云是基于http上传,所以和其他http上传速度基本一致:可以对比其他web系统或网站说附件上传速度.同其他例如 ...

  3. ngxin 添加模块

    if test -n "$NGX_ADDONS"; then echo configuring additional modules for ngx_addon_dir in $N ...

  4. docker 从本地拷贝文件

    1.找到docker的ID全称 docker inspect -f '{{.Id}}' docker_name 2.执行拷贝命令 docker cp 本地文件路径 ID全称:docker路径 3.如果 ...

  5. TeamWork#1,Week 2,Learn In Team

    我觉得做为一个团队,每个人的能力固然重要,但是更重要的是几个人能同心协力. 俗话说“三个臭皮匠,赛过诸葛亮”,团队合作往往能激发出团体不可思议的潜力,集体协作干出的成果往往能超过成员个人业绩的总和.在 ...

  6. 编程之法section II: 2.2 和为定值的两个数

    ====数组篇==== 2.2 求和为定值的两个数: 题目描述:有n个整数,找出其中满足两数相加为target的两个数(如果有多组满足,只需要找出其中一组),要求时间复杂度尽可能低. 解法一: 思路: ...

  7. BNUOJ 52317 As Easy As Possible 树上倍增/主席树

    题目链接: https://acm.bnu.edu.cn/v3/problem_show.php?pid=52317 As Easy As Possible Case Time Limit: 1000 ...

  8. FindBugs插件的使用手册

    安装FindBugs直接查找eclipse的商店,查找spot Bugs 插件,安装即可 完成安装之后重启eclipse,右击项目文件或目录,会发现多了Findbugs的菜单: 使用Findbugs ...

  9. 微信之父张小龙经典演讲164页PPT:《微信背后的产品观》

    收藏地址:http://www.haokoo.com/internet/8974068.html

  10. 安装/卸载 修改Config

    参考地址:https://docs.microsoft.com/zh-cn/nuget/create-packages/source-and-config-file-transformations