Блог пользователя --n--

Автор --n--, история, 4 года назад, По-английски

Please help me solving this problem. I am not getting any idea how to proceed.

You are given an undirected weighed tree with N node . You need to find maximum absolute path sum in the tree with atmost k inversions. In one inversion you can change the weight of an edge from negative to positive and vice versa.

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I solved it in O(n^3), n^2 dp considering one node as root, and O(n^3) by considering every node as root and choosing maximum from them,

My O(n^3) code
Some testcases and ans

But i believe n^2 solution is possible with rerooting DP, i tried that also but I'm somewhat confused in one concept of it

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    no need for rerooting just maintain root to the certain node using $$$X$$$ inversions max possible answer similarly do for children and then chose appropriately. either it could be child-child or child-ancestor for best path sum.

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Can anyone tell what should the dp states be and the corresponding recurrence relation?