HINDI VERSION || C++ || EASY EXPLANATION
I am writing this post in hindi because there are almost no post in hindi.\n\n# Approach\nSimple bas har child ke paas jao and usse ye pucho ki kya uske paas ya
I am writing this post in hindi because there are almost no post in hindi.\n\n# Approach\nSimple bas har child ke paas jao and usse ye pucho ki kya uske paas ya uske child ke paas apple hai ya nahi. Ab code read karo usme comments se ache se explain karne ki try kara hai meine.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(V+E) because normal DFS apply kiya hai toh DFS ki time complexity vertices+edges hoti hai\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(V) because adjancey list banayi hai V vertices ke liye\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int dfs(vector<vector<int>>&adj,int curr,int parent,vector<bool>&hasApple)\n    {\n        int time = 0;\n        for(auto child:adj[curr])\n        {\n            if(child==parent)\n            {\n                continue;\n            }\n            int time_taken_by_child_to_collect_apples = dfs(adj,child,curr,hasApple);\n            if(time_taken_by_child_to_collect_apples>0 or hasApple[child])\n            {\n                time += time_taken_by_child_to_collect_apples + 2;\n            }\n        }\n        return time;\n    }\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<vector<int>>adj(n);\n        for(int i=0;i<edges.size();i++)\n        {\n            adj[edges[i][0]].push_back(edges[i][1]);\n            adj[edges[i][1]].push_back(edges[i][0]);\n        }\n        return dfs(adj,0,-1,hasApple);\n    }\n};\n```\n\nPost read karne ke liye dhanyvaad and agar post se kuch help mili toh please upvote kardena!!!
['Depth-First Search', 'Graph', 'C++']