C++ || DFS || Easy approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(V+E)\n\n- Space complexity:O(V)\n\n# Code\n\nclass Solution {\npublic:\n    int dfs(i
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:$$O(V+E)$$\n\n- Space complexity:$$O(V)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int dfs(int i, int j, vector<int> adj[], vector<bool> &hasApple) {\n        int cnt=0;\n        for(auto it: adj[i]) {\n            if(it!=j) {\n                int num=dfs(it, i, adj, hasApple);\n                if(hasApple[it]){\n                    num+=2; cnt+=num;\n                    hasApple[i]=true;\n                }\n            } \n        }\n        return cnt;\n    }\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<int>adj[n];\n        for(int i=0; i<edges.size(); i++) {\n            adj[edges[i][0]].push_back(edges[i][1]);\n            adj[edges[i][1]].push_back(edges[i][0]);\n        }\n        return dfs(0, 0, adj, hasApple);\n    }\n};\n```
['Depth-First Search', 'Graph', 'C++']