C++ 2 line DFS Solution 2023 Must Watch.
\nclass Solution {\n    vector<vector<int>> graph;\n    int dfs(int root,vector<bool>& hasApple, int par = -1, int ans = 0){\n        for(auto node:graph[root])
```\nclass Solution {\n    vector<vector<int>> graph;\n    int dfs(int root,vector<bool>& hasApple, int par = -1, int ans = 0){\n        for(auto node:graph[root]) if(node!=par) ans += dfs(node,hasApple,root);\n        return (!root) ? ans : (hasApple[root] || ans) ? ans + 2 : 0 ;\n    }\npublic:\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        graph.resize(n);\n        for(auto it:edges) graph[it[0]].emplace_back(it[1]), graph[it[1]].emplace_back(it[0]);\n        return dfs(0,hasApple);\n    }\n};\n```
['Tree', 'Depth-First Search', 'Graph', 'Recursion', 'C', 'Binary Tree', 'C++']