✅[C++] | DFS | Detailed Code with comments✅
DFS\n\nclass Solution {\npublic:\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<bool> visited(n, false);\n\n     
### DFS\n```\nclass Solution {\npublic:\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<bool> visited(n, false);\n\n        // Make Adjacency Graph\n        vector<vector<int>> graph(n);\n        for(auto& edge: edges) {\n            graph[edge[0]].push_back(edge[1]);\n            graph[edge[1]].push_back(edge[0]);\n        }\n\n        // Visit 0 as it is the beginning\n        visited[0] = true;\n        return dfs(0, n, graph, hasApple, visited);\n\n    }\n\n    int dfs(int start, int n, vector<vector<int>>& graph, vector<bool>& hasApple, vector<bool>& visited) {\n        int time = 0, childTime;\n\n        // For each adjacent unvisited node of start, perform dfs\n        for(auto i: graph[start]) {\n            if(!visited[i]) {\n                // Calculating the child \'i\' time \n                visited[i] = true;\n                childTime = dfs(i, n, graph, hasApple, visited);\n\n                // * childTime == 0 implies that the child \'i\' does not have any apples\n                // * If child \'i\' has apples, then add it to the total time. \n                // * Add 2 to it as it takes +2 from \'i\' to parent.\n                if(childTime != 0 || hasApple[i])\n                    time += (childTime + 2);\n            }\n        }\n\n        return time;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Graph', 'C++']