当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5877:Weak Pair

题目描述
You are given a $rooted$ tree of $ N $ nodes, labeled from 1 to $ N $. To the $ i $th node a non-negative value $ a_i $ is assigned.An $ordered$ pair of nodes $ (u, v) $ is said to be $weak$ if
  (1) $ u $ is an ancestor of $ v $ (Note: In this problem a node $ u $ is not considered an ancestor of itself);
  (2) $a_u\times a_v \le k$.

Can you find the number of weak pairs in the tree?
输入解释
There are multiple cases in the data set.
  The first line of input contains an integer $ T $ denoting number of test cases.
  For each case, the first line contains two space-separated integers, $ N $ and $ k $, respectively.
  The second line contains $ N $ space-separated integers, denoting $ a_1 $ to $ a_N $.
  Each of the subsequent lines contains two space-separated integers defining an edge connecting nodes $u$ and $ v $ , where node $ u $ is the parent of node $ v $.

  Constrains:
  
  $ 1 \le N \le 10^5 $
  
  $ 0 \le a_i \le 10^9 $
  
  $ 0 \le k \le 10^{18} $
输出解释
For each test case, print a single integer on a single line denoting the number of weak pairs in the tree.
输入样例
1
2 3
1 2
1 2
输出样例
1
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5877

最后修改于 2020-10-25T23:26:23+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 262144/262144K(Java/Others)