Count Participating Edges || C++Good Code Quality DFS with explanation.
Intuition\n\n\nIn the above example we can observe that edges that have apples as \ndescendants are participating in the tour to get all the apples.We can count
# Intuition\n![image.png](https://assets.leetcode.com/users/images/b01e680c-3cfa-4bce-b9b9-215fa5129edd_1673423460.731038.png)\n\nIn the above example we can observe that edges that have apples as \ndescendants are participating in the tour to get all the apples.We can count these edges and multiply by 2 as we have to visit and get back to them and can return the answer.\n\n\n# Approach\nStandard DFS where we traverse the tree and if there are apples or edges that have apples as childs or descendants then we update parents to count these edges and if we didn\'t find any then we didn\'t count any edges.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(V+E)$$ (Standard DFS Time Complexity)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(V+V)$$ ~ $$O(V)$$ \nV space for adjacency list and V space for auxilary recursive call stack space.\n\n# Code\n```\nclass Solution {\npublic:\n    int dfs(int node,int parent,vector<vector<int>>& adj,vector<bool>& hasApple){\n        int edges = 0;\n        for(auto child : adj[node]){\n            if(child==parent) continue;\n            edges += dfs(child,node,adj,hasApple);\n        } \n        if(node==0) return edges;\n        if(edges>0 || hasApple[node]){\n            return edges+1;\n        }\n        return edges;\n    }\n\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<vector<int>> adj(n);\n        for(auto edge : edges){\n            adj[edge[0]].push_back(edge[1]);\n            adj[edge[1]].push_back(edge[0]);\n        }\n        return 2*dfs(0,-1,adj,hasApple);\n    }\n};\n```
['Tree', 'Depth-First Search', 'C++']