C++ || Normal DFS || Easy Code || (Microsoft)dfs
Complexity\nHere, n be the number of nodes.\n- Time complexity: O(n) \n\n- Space complexity: O(n) \n\n# Code\nThere would be no cycle beacuse it is a tree. As m
# Complexity\nHere, n be the number of nodes.\n- Time complexity: $$O(n)$$ \n\n- Space complexity: $$O(n)$$ \n\n# Code\nThere would be no cycle beacuse it is a tree. As mentioned, size of array edges is n-1.\n```\nclass Solution {\npublic:\n\n    int dfs(int node, int n, vector<int> *adj, vector<bool> &hasApple, vector<bool> &visited){\n        visited[node]=true;\n        int time=0;\n        for(auto child: adj[node]){\n            if(!visited[child]){\n                int time_from_child=dfs(child,n,adj,hasApple,vis);\n                if(time_from_child >0 || hasApple[child]){\n                    time+= (time_from_child+2);\n                }\n            }\n        }\n        return time;\n    }\n\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<int> adj[n];\n        vector<bool> visited(n,false);\n        for(auto it: edges){\n            adj[it[0]].push_back(it[1]);\n            adj[it[1]].push_back(it[0]);\n        }\n        return dfs(0,n,adj,hasApple,vis);\n    }\n};\n```\n## Please! hit the UPVOTE button...
['Tree', 'Depth-First Search', 'Graph', 'C++']