Python solution with DFS + BFS , beats 100%
\n# Definition for a binary tree node.\nclass TreeNode:\n    def __init__(self, x):\n        self.val = x\n        self.left = None\n        self.right = None\n
```\n# Definition for a binary tree node.\nclass TreeNode:\n    def __init__(self, x):\n        self.val = x\n        self.left = None\n        self.right = None\n\nclass Solution:\n    def distanceK(self, root, target, K):\n        """\n        :type root: TreeNode\n        :type target: TreeNode\n        :type K: int\n        :rtype: List[int]\n        """\n        parent = {}\n        visited = {}\n        def dfs(parent, pre, curr, visited):\n            if not curr:\n                return\n            visited[curr] = False\n            parent[curr] = pre\n            dfs(parent, curr, curr.left, visited)\n            dfs(parent, curr, curr.right, visited)\n        \n        dfs(parent, None, root, visited)\n        \n        dis = 0\n        queue = []\n        queue.append(target)\n        \n        while len(queue) != 0:\n            if dis == K:\n                break\n            tmp = []\n            for node in queue:\n                visited[node] = True\n                if node.left != None and visited[node.left] == False:\n                    tmp.append(node.left)\n                if node.right != None and visited[node.right] == False:\n                    tmp.append(node.right)\n                if parent[node] != None and visited[parent[node]] == False:\n                    tmp.append(parent[node])\n            queue = tmp\n            dis += 1\n        res = [node.val for node in queue]\n        return res\n```
[]