[C++] Easy and Concise
Explanation\nBuild Adj List representation of undirected graph.\nRun DFS from root node but keep track of parent node. \nGo through all edges of ith node except
# Explanation\nBuild Adj List representation of undirected graph.\nRun DFS from root node but keep track of parent node. \nGo through all edges of ith node except for the parent node.\nReturn steps + 2 if the the ith element is carrying more than 1\napple or if there exists an apple at the ith node.\nOtherwise return steps.\n\n# Edge Case\nDon\'t return steps+2 if at the root node\n\n# Complexity\n- Time complexity:\nO(N) as we traverse through each node exactly once.\n\n- Space complexity:\nO(N) due to recursive call stack and adj list.\n\n# Code\n```\nclass Solution {\npublic:\n    int dfs(int node, vector<int> adj[], vector<bool>& hasApple, int parent) {\n        int steps = 0;\n        for (auto edge : adj[node]) {\n            if (edge != parent)\n                steps += dfs(edge,adj,hasApple,node);\n        }\n        if ((hasApple[node] || steps > 0 )&& node != 0 ) {\n            return steps + 2;\n        }\n        return steps;\n    }\n\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<int> adj[n];\n        int size = edges.size();\n        for (auto edge : edges) {\n            adj[edge[0]].push_back(edge[1]);\n            adj[edge[1]].push_back(edge[0]);\n        }\n        return dfs(0,adj,hasApple,-1);\n    }\n};\n```
['Depth-First Search', 'C++']