C++ Solution
\n/*\nTo visit a node from a parent the cost is 2. Because I visit the node and backtrack which is considered to the cost.\n\nI have to count only the cost of c
```\n/*\nTo visit a node from a parent the cost is 2. Because I visit the node and backtrack which is considered to the cost.\n\nI have to count only the cost of collecting the apples present in the nodes and not count unnecessary nodes.\nHow do we do that?\n\nWe use a dfs finction to help us with that.\nWe have 5 parameters\n1. A build graph adjacncy list\n2. A vector bool array to help us not visit a node multiple times\n3. A node which is passed as 0 initially.\n4. Cost variable which will be 2 more that the previous one because of the fact i told about earlier\n5. hasApple array.\n\nThe dfs will help us with finding the cost by the following method:-\n\n1. If I find out that atleast one of my children have nodes i return the cost and the children cost to the call stack.\n2. If I find out that none of the children contains apples we return 0.\n*/\n    vector<bool> vis;\n    int dfs(vector<vector<int>> &graph,vector<bool>& hasApple,int node,int cost)\n    {\n        if(vis[node])return 0;\n        vis[node]=true;\n        int children_cost=0;\n        for(auto x:graph[node])\n            children_cost+=dfs(graph,hasApple,x,2);\n        if(children_cost==0 && hasApple[node]==false)return 0;\n        return (children_cost+cost);\n    }\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<vector<int>> graph(n);\n        vis=vector<bool>(n,false);\n        for(auto &x:edges)\n        {\n            graph[x[0]].push_back(x[1]);\n            graph[x[1]].push_back(x[0]);\n        }\n        return dfs(graph,hasApple,0,0);\n    }\n```
['C', 'C++']