[C++] Short and simple DFS
Observation\nWe know that graph is in a form of tree i.e no cycles and that the last node is supposed to be the root it self, this gives us an idea that we can 
**Observation**\nWe know that graph is in a form of tree i.e no cycles and that the last node is supposed to be the root it self, this gives us an idea that we can use DFS to solve this.\nAt each node we can check if its children has any apples if it does we add the distance from current node to that child node and we return this distance else we return `0`.\nThe other key observation is that each time we collect the apple we have to walk back to the parent, thus the distance travelled is doubled.\n\n**Solution**\nWe can return the distance as 0 if no apples found under the node and the current node also doesn\'t have an apple else we return the distance travelled.\n\n```c++\nclass Solution {\npublic:\n    vector<vector<int>> adjList;\n    int dfs(vector<bool>& hasApple,int node,int d,int prev)\n    {\n        int result=0,temp;\n        for(int &i:adjList[node])\n\t    if(i!=prev)\n\t    {\n\t        temp=dfs(hasApple,i,d+1,node);\n\t        if(temp)\t\t\t//If child has apples it\'ll return a non zero result which is the distance traveled upto that node.\n\t\t    result+=temp-d;\n\t    }\n        return result||hasApple[node]?result+d:0;  //If nothing is added to result and current node doesnt have apple return 0 else return distances of children + current distance from root.\n        \n    }\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) \n    {\n        adjList.resize(n);\n        for(vector<int> &e:edges)\n            adjList[e[0]].push_back(e[1]),adjList[e[1]].push_back(e[0]);\n        return dfs(hasApple,0,0,-1)*2;     //Result is doubled the distance travelled as per our observation.\n    }\n};\n```
[]