CPP DFS+BFS solution.
\nclass Solution {\n    void dfs(TreeNode* root, unordered_map<TreeNode*, TreeNode*>& m) {\n        if(!root) return;\n        if(root->left) {\n            m.i
```\nclass Solution {\n    void dfs(TreeNode* root, unordered_map<TreeNode*, TreeNode*>& m) {\n        if(!root) return;\n        if(root->left) {\n            m.insert({root->left, root});\n        }\n        if(root->right) {\n            m.insert({root->right, root});\n        }\n        dfs(root->left, m);\n        dfs(root->right, m);\n    }\npublic:\n    vector<int> distanceK(TreeNode* root, TreeNode* target, int k) {\n        unordered_map<TreeNode*, TreeNode*> m; //{current, parent}\n        queue<TreeNode*> q;\n        dfs(root, m);\n        q.push(target);\n        vector<int> res;\n        unordered_map<TreeNode*, bool> visited;\n        while(!q.empty()) {\n            int len = q.size();\n            while(len--) {\n                TreeNode* curr = q.front(); q.pop();\n                if(!k) res.push_back(curr->val);\n                visited[curr] = true;\n                if(curr->left && !visited[curr->left]) {\n                    q.push(curr->left);\n                }\n                if(curr->right && !visited[curr->right]) {\n                    q.push(curr->right);\n                }\n                if(m.find(curr) != m.end() && visited[m[curr]] == false) {\n                    q.push(m[curr]);\n                }\n            }\n            k--;\n            if(k < 0) break;\n        }\n        return res;\n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Queue', 'C', 'C++']