Given a tree and Q queries to be answered. In each query you will be provided with 2 nodes u & v. You should return the path, like u -> v1 -> v2... -> v
I have a naive approach to perform DFS for each query but can it be made any better? Is any kind of pre-processing possible? (I'm new to graphs! Kindly help me and also correct me if I went wrong somewhere)