gXa's blog

By gXa, history, 7 years ago, In English

A tree is given in which each edge is having some weight associated with it and you are given a number K.

So starting from root in K-steps how much maximum weight you can collect. You can traverse in any direction either from parent to child or child to parent. You can visit a node multiple times.

~~~~~ ~~~~~

Spoiler
  • Vote: I like it
  • -2
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +13 Vote: I do not like it

I have not formally proved this, but say we use the edges e1, e2, e3, ..., ek (these are the weights). So sum over all ei is less than k * max(ei), i.e, it is better to repeat the max edge k times. So this may lead to a greedy algorithm. For each edge, if the depth of the node is d, add the weight upto that depth, and then add the edge k - d times. Find the maximum for all edges.