Doubt in below question

https://codeforces.com/contest/1006/problem/E

I know how to use euler tour here but not able to understand how to find particular element on that index
help me out

@yashme7125 we will travel the tree and store the order of nodes and also we will sort the list of the nodes first as demanded in the question the nodes visited should be in the assending order and we also store the size of subtree of every node then we have 2 cases for each query
a is the node
b is the kth node
two cases are

  1. b is greater than the size of the subtree (a) then we print -1 direct
  2. else
    we get the starting position of this code (this can be done by stroing the index of
    every element in the order of traversal) then suppose it is at index id
    then we print the element at index (id+b-1) in the order of the traversal

here is the code
Coding Blocks IDE
if you still have any dout let me know and if clear please rate my experience…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.


Sir, can you check my code and tell what’s wrong in this it’s almost same as you told
but giving me segmention fault.

@yashme7125 in start of your code resize the vector idx to n+1 or use map instead of a vector idx use map<int,int> idx