HBC15541Counting On A Tree Again题解

把回忆走一遍 算法基础篇 48 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
You are given an undirected tree of n vertices rooted at 1. Vertices are numbered from 1 to n. The ith node has the value ai. Then there are q queries, each of them contains two integers: x,k. For each query, you are required to count how many pairs of (i,j) that satisfy the following condition: 1. ai= x. 2. |ai aj| ≤ k. 3. The jth node is an ancestor of the ith node.

You are given an undirected tree (a connected acyclic undirected graph) of n vertices rooted at 1. Vertices are numbered from 1 to n. The ith node has the value ai. Then there are q queries, each of them contains two integers: x,k. For each query, you are required to count how many pairs of (i,j) that satisfy the following condition: 1. ai= x. 2. |ai− aj| ≤ k. 3. The jth node is an ancestor of the ith node.

HBC15541Counting On A Tree Again题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
全网最全C++题库,助您挑战自我,突破极限,成为编程领域的佼佼者!

标签: HBC15541Counting On A Tree Again题解