C++ | DFS | Clean | O(n+v)
\nclass Solution {\npublic:\n    int solve(int node,\n              const vector<vector<int>>& tree,\n              const vector<bool>& hasApple,\n             
```\nclass Solution {\npublic:\n    int solve(int node,\n              const vector<vector<int>>& tree,\n              const vector<bool>& hasApple,\n              vector<bool>& visited){\n        visited[node] = true;\n        int depth = 0;\n        for(const auto& child: tree[node]){\n            if(!visited[child]){\n                depth+=solve(child, tree, hasApple, visited);\n            }\n        }\n        return (depth ||  hasApple[node])? depth + 1: 0;\n    }\n\n    int minTime(int n,\n                vector<vector<int>>& edges,\n                vector<bool>& hasApple) {\n        vector<vector<int>> tree(n);\n        vector<bool> visited(n);\n        for(const auto& edge: edges) {\n            tree[edge[0]].push_back(edge[1]);\n            tree[edge[1]].push_back(edge[0]);\n        }\n        return max(0, 2* (solve(0, tree, hasApple, visited) - 1));\n    }\n};\n```
['Depth-First Search', 'C']