Simple DFS| C++
Intuition\n Describe your first thoughts on how to solve this problem. \nSimply we have to traverse those branches or sub trees which will have apple and those 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply we have to traverse those branches or sub trees which will have apple and those will counted in time so check if there is a child which has apple it will be counted and increment the time accordingly.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust do dfs and check if child has apple find its height form rooot node that will be its time and at last just multiply ans by 2 because\nbeacuse we doing bidirectional first traversing and then returning so two traversals for each node . So only those will be counted who conatain apple.\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n) --> Recursive stack\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nvector<vector<int>>adj;\n    int dfs(int par,int node,vector<bool>&hasApple,int dis){\n        int disRoot=0,disChild=0;\n        for(auto x:adj[node]){\n            if(x!=par)\n            disRoot=dfs(node,x,hasApple,dis+1);\n            if(disRoot)\n            disChild+=disRoot-dis;\n        }\n        return (disChild || hasApple[node])?disChild+dis:0;\n    }\n     \n   \n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n       // int n=edges.size();\n        \n        adj.resize(n);\n        for(auto e:edges){\n           adj[e[0]].push_back(e[1]);\n           adj[e[1]].push_back(e[0]);\n        }\n        int dis=0;\n        return dfs(-1,0,hasApple,dis)*2;\n        \n    }\n};\n```
['Depth-First Search', 'C++']