c++ 93% faster solution trying all subsets using bitmask
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nint answer=0;\nint nodes=0;\nint dfs(int node,int par,vector<vector<int>>& adj,int& mask){\n    int a=INT_MIN;\n    int b=INT_MIN;\n    int maxi=0;\n    nodes++;\n    for(int & i: adj[node]){\n        if(i!=par && mask & (1<<i)){\n            int res=1+dfs(i,node,adj,mask);\n            maxi=max(maxi,res);\n            if(a<res){\n                b=a;\n                a=res;\n            }\n            else if(b<res){\n                b=res;\n            }\n            \n        }\n    }\n    if(a!=INT_MIN && b!=INT_MIN){\n        answer=max(answer,a+b);\n    }\n    answer=max(answer,maxi);\n    return maxi;\n}\nvoid subsets(int ind,int n,int s,vector<vector<int>>& adj,int mask,vector<int>& ans){\n    if(ind==n){\n        return;\n    }\n    // not_take\n    subsets(ind+1,n,s,adj,mask,ans);\n    // take\n    s++;\n    mask=mask | (1<<ind);\n    if(s>1){\n        answer=0;\n        nodes=0;\n        dfs(ind,-1,adj,mask);\n        if(nodes==s){\n            ans[answer-1]++;\n        }\n    }\n    subsets(ind+1,n,s,adj,mask,ans);\n}\n    vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        vector<int> ans(n-1,0);\n        vector<vector<int>> adj(n);\n        for(auto& ele: edges){\n            adj[ele[0]-1].push_back(ele[1]-1);\n            adj[ele[1]-1].push_back(ele[0]-1);\n        }\n        subsets(0,n,0,adj,0,ans);\n        return ans;\n    }\n};\n```
['C++']