✔️ Easy C++ Solution
Solution\n\nC++ []\nclass Solution {\npublic:\n    vector<vector<int>> adjList;\n    int dfs(vector<bool>& hasApple,int node,int d,int prev)\n    {\n        int
# Solution\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) result+=temp-d;\n\t    }\n        return result||hasApple[node]?result+d:0; \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;\n    }\n};\n```\n\n![kitty.jpeg](https://assets.leetcode.com/users/images/033de1fd-1964-4a54-ba93-ea5ca1181e61_1674563847.7582145.jpeg)
['C++']