cswork / OA打开练习工作台

MillenniumOA #2

Warehouse Tree Compatible Pairs

估计困难评测数据准备中,可先阅读题面

考点(AI 标注)二分查找树的遍历

A network of warehouses is an undirected rooted weighted tree with warehouse_nodes nodes rooted at warehouse 1. Each node has a value val[v]. A pair (u, v) is compatible iff:

  • u is an ancestor of v in the tree.
  • distance(u, v) ≤ val[v].

Count compatible pairs.

Example: with the input from the OA, the answer is 5.

Constraints

  • 1 ≤ warehouse_nodes ≤ 1.5·10⁵
  • 1 ≤ warehouse_weight[i] ≤ 10⁴
  • 1 ≤ val[i] ≤ 10⁹