Python Graph solution // 44 ms
\nclass Solution:\n    def distanceK(self, root, target, K):\n        adj, res, visited = collections.defaultdict(list), [], set()\n        def dfs(node):\n    
```\nclass Solution:\n    def distanceK(self, root, target, K):\n        adj, res, visited = collections.defaultdict(list), [], set()\n        def dfs(node):\n            if node.left:\n                adj[node].append(node.left)\n                adj[node.left].append(node)\n                dfs(node.left)\n            if node.right:\n                adj[node].append(node.right)\n                adj[node.right].append(node)\n                dfs(node.right)\n        dfs(root)\n        def dfs2(node, d):\n            if d < K:\n                visited.add(node)\n                for v in adj[node]:\n                    if v not in visited:\n                        dfs2(v, d + 1)\n            else:\n                res.append(node.val)\n        dfs2(target, 0)\n        return res\n```
[]