Simple C++ code by brutal force bit mask
\nint countSubgraphsForEachDiameter_(int startIdx, int& nodes, vector<vector<int>>& conn, int& visited, int& maxDepth) {\n\tvisited |= (1 << startIdx);\n\tint f
```\nint countSubgraphsForEachDiameter_(int startIdx, int& nodes, vector<vector<int>>& conn, int& visited, int& maxDepth) {\n\tvisited |= (1 << startIdx);\n\tint first = 0, second = 0;\n\n\tfor (int i = 0; i < conn[startIdx].size(); ++i) {\n\t\tif ((nodes & (1 << conn[startIdx][i])) && !(visited & (1 << conn[startIdx][i]))) {\n\n\t\t\tint depth = countSubgraphsForEachDiameter_(conn[startIdx][i], nodes, conn, visited, maxDepth);\n\n\t\t\tif (depth >= first) {\n\t\t\t\tsecond = first;\n\t\t\t\tfirst = depth;\n\t\t\t} else {\n\t\t\t\tsecond = max(second, depth);\n\t\t\t}\n\n\t\t}\n\t}\n\n\tmaxDepth = max(maxDepth, first + second);\n\treturn first + 1;\n}\n\nvector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n\n\tvector<int>  res(n - 1, 0);\n\tvector<vector<int>> conn(n);\n\n\tfor (int i = 0; i < edges.size(); ++i) {\n\t\tconn[edges[i][0] - 1].push_back(edges[i][1] - 1);\n\t\tconn[edges[i][1] - 1].push_back(edges[i][0] - 1);\n\t}\n\n\tfor (int i = 1; i < (1 << n); ++i) {\n\t\tint maxDepth = 0;\n\t\tint visited = 0;\n\n\t\tint startIdx = 0;\n\n\t\tfor (; (i & (1 << startIdx)) == 0; ++startIdx);\n\n\t\tcountSubgraphsForEachDiameter_(startIdx, i, conn, visited, maxDepth);\n\n\t\tif ((visited == i) && maxDepth > 0) ++res[maxDepth - 1];\n\n\t}\n\n\treturn res;\n}\n```
[]