Shikimaru has queries

Shikamaru has Queries
My submission

Approach:

I believe finding the shortest path is the answer.

  1. Perform bfs, starting from source
  2. For every node visited, store its value in the array
  3. If destination is found, break the loop.

For a tree with the query and nodes mentioned below, array would be:
1 3 2
1 2
2 3
1 4
4 5
[[1], [1, 2], [1, 2, 3], [1, 4], [5]]

The shortest path to destination should be found at ( destination-1 )th index.

Can anyone help me what is it that I am missing?