Approach hintTry it first, then revealHide
Record every node's parent in one traversal, then treat the tree as an undirected graph and run a BFS from the target for exactly k layers, marking visited nodes.
Record every node's parent in one traversal, then treat the tree as an undirected graph and run a BFS from the target for exactly k layers, marking visited nodes.