A code that passes but is wrong , Lets Discuss Why:)
Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea was to create the tree, using a vector of vectors where position is the vertex
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea was to create the tree, using a vector of vectors where position is the vertex and the vector stored in it is the number of vertex it is connected to\nThen checking where the apples are using dfs\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreated a tree using vector of vectors\nApply DFS, whenever there is a vertex with apple add 2 to the answer and set the parent vertex of the current vertex to true in the has apple array,(This helps to create a pathway)\nFinally returning the total time\n\n# Complexity\n- Time complexity: O(N), N being the number of vertices\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N), I have taken Set to check for the children nodes\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution\n{\npublic:\n    int ans = 0;\n    vector<vector<int>> mp;\n    void dfs(int st, vector<bool> &a)\n    {\n        if (mp[st].empty())                // If the current vector is empty\n            return;                        // No children to traverse, return\n        vector<int> v = mp[st];            // Store the current set of child nodes\n        for (int i = 0; i < v.size(); i++) // Traverse the current lot\n        {\n            dfs(v[i], a); // Check for the children nodes of the current nodes\n\n            if (a[v[i]])  // If the current node has an apple\n                          // Add 2 to the answer\n                          // Set the parent node in the hasApple array to true,\n                          // This creates a pathway back to the node 0,\n                          // adding 2s along the way\n                ans += 2, a[st] = true;\n        }\n    }\n    int minTime(int n, vector<vector<int>> &edges, vector<bool> &hasApple)\n    {\n        // Create the tree\n        mp.resize(n);\n        unordered_set<int> st;\n        for (vector<int> c : edges)\n            if (st.find(c[1]) != st.end()) // if the current child node is a child of an existing node,\n                                           // set it as a parent this time\n                mp[c[1]].push_back(c[0]), st.insert(c[0]);\n            else // Else setup the current child and parent node\n                mp[c[0]].push_back(c[1]), st.insert(c[1]);\n        // Do the DFS\n        dfs(0, hasApple);\n        return ans;\n    }\n};\n```
['C++']