DFS || C++
Code\n\nclass Solution {\npublic:\n    int solve(int s,int p,vector<vector<int>> &g, vector<bool>& v){\n        int k = 0;\n        for(auto &i: g[s]){\n       
# Code\n```\nclass Solution {\npublic:\n    int solve(int s,int p,vector<vector<int>> &g, vector<bool>& v){\n        int k = 0;\n        for(auto &i: g[s]){\n            if(i != p){\n                \n                k += solve(i,s,g,v);\n                \n            }\n        }\n        if(v[s]==true || k)return k+2;\n        return k;\n    }\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& v) {\n        vector<vector<int>> g(n);\n        for(auto &i: edges){\n            g[i[0]].push_back(i[1]);\n            g[i[1]].push_back(i[0]);\n        }\n        int k = solve(0,-1,g,v);\n        if(k>2)return k-2;\n        return 0;\n    }\n};\n```
['Tree', 'Depth-First Search', 'C++']