Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

Σ f(u,   v) for all pair of u, v

Revision en1, by Confused101, 2017-04-27 07:34:44

I recently saw a problem in some online judge where I was given a tree and was asked the value of Σ f(u, v) for all pair of u, v where f is some function that takes two nodes u, v of a graph. for example f(u, v) can be any of these.

1) f(u, v) = distance between u, v in a weighted tree.
2) If every nodes have number written, f(u, v) can be median / mode / average/ sum of all numbers in path from u to v.
3) if every nodes have colors assigned f(u, v) can be number of distinct colors between path from u to v.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Confused101 2017-04-27 07:36:02 49
en1 English Confused101 2017-04-27 07:34:44 579 Initial revision (published)