How to count the number of pair of paths in a rooted tree whose sum=k ?

Правка en2, от codemode, 2019-06-29 15:32:23

We are given a rooted tree with 'n' vertices, where , n<=10^5.

For the problem : Count the number of paths in a tree with sum=k .

I don't know its efficient solution.

And now the new problem is : —

Count the number of pair of paths in a rooted tree with sum=k.

Example, say the path(2-5) in a tree has sum=8, and another path (7-9) in the same tree has sum=9.

So the pair of paths:- {(2-5),(7-9)} has a sum=8+9=17.

Can I get some ideas on how to solve both of these problems ?

Теги #trees

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский codemode 2019-06-29 15:32:23 1 Tiny change: 'n I get soe ideas on' -> 'n I get some ideas on'
en1 Английский codemode 2019-06-29 15:31:04 577 Initial revision (published)