Simple DFS solution with Pre-calculation.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    int dp[100002];\n    int ans[100002];\n    int calculateDepth(TreeNode* root, int currentDepth) {\n        if(root == nullptr) {\n            return 0;\n        }\n        int left = calculateDepth(root->left, currentDepth+1);\n        int right = calculateDepth(root->right, currentDepth+1);\n        dp[root->val] = max(left, right);\n        return dp[root->val] + 1;\n\n    }\n    void calculateAnswer(TreeNode* root, int maxOfPrev, int depthFormTop) {\n        if(root == nullptr) {\n            return;\n        }\n        int leftMax = root->left == nullptr ? 0 : dp[root->left->val] + 1;\n        int rightMax = root->right == nullptr ? 0 : dp[root->right->val] + 1;\n        ans[root->val] = maxOfPrev;\n        calculateAnswer(root->left, max(maxOfPrev, rightMax + depthFormTop), depthFormTop + 1);\n        calculateAnswer(root->right, max(maxOfPrev, leftMax + depthFormTop), depthFormTop + 1);\n        return;\n\n    }\n    vector<int> treeQueries(TreeNode* root, vector<int>& queries) {\n        memset(dp, 0, sizeof(dp));\n        calculateDepth(root, 0);\n        calculateAnswer(root, 0, 0);\n        vector<int>fAns;\n        for(int i=0;i<queries.size();i++) {\n            fAns.push_back(ans[queries[i]]);\n        }\n        return fAns;\n    }\n};\n```
['Depth-First Search', 'C++']