Actually you bring up a good point. You can still use DFS if the other conditions are met. Namely, if the graph is a tree, there exists only one path from a node to any other node. Therefore that path is also the shortest path and the edge weights do not matter. Thank you for bringing that up Madhuri. I will correct that.