Here is an Easy Problem of Zero-chan题解报告

先看段巨佬代码 戳这里 自认为比较好懂,可以看看。
题目来源:https://ac.nowcoder.com/acm/contest/38727/H
来源:牛客网
题目描述
Zero-chan has a rooted tree with nn nodes. The root of given tree is node 1. She defines
f ( x ) = ∏ i = 1 n l c a ( x , i ) . f(x)=\prod_ {i=1}^nlca(x,i). f(x)=i=1nlca(x,i).
l c a ( x , i ) lca(x,i) lca(x,i)meas the Least Common Ancestor of node uu and node v.
Zero-chan gives you some integers xx and asks you to calculate: the number of suffix zeros of f ( x ) f(x) f(x)
输入描述:
First line contains 2 integers n , q ( 1 < = q < = n < = 1 0 5 ) n,q (1<=q<=n<=10^5) n,q(1<=q<=n<=105) the size of given tree and the number of queries.

Each of the next n − 1 n-1 n1 lines contains two integers u , v ( 1 < = u , v < = n , u ! = v ) u,v(1<=u,v<=n,u!=v) u,v(1<=u,v<=n,u!=v) indicating an undirected edge between node u and node v. It is guaranteed that the given edges form a tree.

The following line containing qq integers describes the queries. Each of query has a integer x ( 1 < = x < = n ) . x(1<=x<=n). x(1<=x<=n).
输出描述:
For each query, print a integer - the answer of the query.
示例1
输入

5 5
2 3
5 4
2 5
1 5
1 2 3 4 5

输出

0
2
1
2
0

题目大意

题目解析
(各位巨佬就不用了听我婆婆妈妈了,直接看献上代码就行)
题目简单,做起来让我CE,TLE,WA了无数。。。(哪来的傻冒?
开始,我是这样想的:先将树读入后,预处理,然后,输入x,去枚举i~n,分别求出每个x和i的lca,用ans记录其lca的乘积,最后判断其后缀0的个数,时间复杂度为 O ( n l o g n + q n l o g n

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值