Tree Problem

Правка en1, от giorgosgiapis, 2018-09-10 19:12:18

So I came up with this problem yesterday, which I couldn't solve. With a quick google search I found nothing relevant so I thought I could ask here for help.

The Problem

You are given a tree T with n nodes and an integer k. You are asked to find the length of longest path in T which has exactly k inversions. Here we define path inversions for a specific path P as the number of inversions in the array of the nodes visited in P, in that order. If there is no such path output  - 1.

Let's consider the above tree for example, with k = 2. The answer is 4 since the path 1 - 6 - 2 - 5 has exactly 2 inversions. Note that the path 4 - 2 - 5 also has 2 inversion however it isn't the path with the maximum length.

Since I don't know how this is solved I cannot give constrains. Any solution with reasonable complexity is welcome.
Thank you for your time.

Теги tree, inversions

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский giorgosgiapis 2018-09-10 21:46:03 4 Typo fixed
en3 Английский giorgosgiapis 2018-09-10 19:36:43 2 fixed typo
en2 Английский giorgosgiapis 2018-09-10 19:16:16 109 Tiny change: '(n^3 logn)<br>\nThan' -> '(n^3 logn)$<br>\nThan'
en1 Английский giorgosgiapis 2018-09-10 19:12:18 971 Initial revision (published)