Bitmasking and FloyWarshall
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:\n    int solve(int mask , vector<vector<int>>&dist , int n)\n    {\n        // ab aap dekhiye \n        // me vhi nodes include krunga jo link me h \n        // complete tree ke liye har nodes ek dusre se connect honi chahiye \n        int node =0 ;\n        int edge = 0;\n        int maxi = 0;\n        for(int i = 0; i <  n ; i++)\n        {\n            if(((mask>>i) & 1)==1)\n            {\n                node++;\n                for(int j =i +1 ; j < n ; j++)\n                {\n                    if(((mask>>j)&1)==1)\n                    {\n                        if(dist[i][j] == 1)edge++;\n                        maxi = max(maxi , dist[i][j]);\n                    }\n                }\n            }\n        }\n        if(node == edge +1 )return maxi;\n        else return -1;\n        \n    }\n    vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& e) {\n        \n        vector<int>a(n-1 , 0);\n        vector<vector<int>>dist(15 , vector<int>(15 ,  INT_MAX));\n        for(auto i : e)\n        {\n            dist[i[0]-1][i[1]-1] = dist[i[1]-1][i[0]-1] = 1;\n        }\n        // ab aap minimum distance nika lijiye floyd warshall algo se \n        for(int i = 0 ; i  < n ; i++)\n        {\n            for(int j = 0 ; j < n ; j++)\n            {\n                for(int k =0; k<n ; k++)\n                {\n                    if(dist[j][i]!=INT_MAX and dist[i][k]!=INT_MAX)\n                        dist[j][k] = dist[k][j] = min({dist[j][k] , dist[j][i] + dist[i][k]});\n                }\n            }\n        }\n        // ab mere pass minimum distance aa gyi h basically me har subset of nodes\n        // ke liye try krunga ki usme maximum distance between nodes kitni ho rhi h\n        // aur us particular distance me ++ kr dunga \n        for(int i = 0; i < (1<<n) ; i++)\n        {\n            // i denoting mask means 1111 -> denotes include node 1 ,2,3,4\n            int ans = solve(i , dist , n);\n            if(ans > 0)\n                a[ans-1]++;\n        }\n        return a;\n\n    }\n};\n```
['C++']