C++ solution
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 {\n public:\n  vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n    const int maxMask = 1 << n;\n    const vector<vector<int>> dist = floydWarshall(n, edges);\n    vector<int> ans(n - 1);\n\n    // mask := subset of cities\n    for (int mask = 0; mask < maxMask; ++mask) {\n      const int maxDist = getMaxDist(mask, dist, n);\n      if (maxDist > 0)\n        ++ans[maxDist - 1];\n    }\n\n    return ans;\n  }\n\n private:\n  vector<vector<int>> floydWarshall(int n, const vector<vector<int>>& edges) {\n    vector<vector<int>> dist(n, vector<int>(n, n));\n\n    for (int i = 0; i < n; ++i)\n      dist[i][i] = 0;\n\n    for (const vector<int>& edge : edges) {\n      const int u = edge[0] - 1;\n      const int v = edge[1] - 1;\n      dist[u][v] = 1;\n      dist[v][u] = 1;\n    }\n\n    for (int k = 0; k < n; ++k)\n      for (int i = 0; i < n; ++i)\n        for (int j = 0; j < n; ++j)\n          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);\n\n    return dist;\n  }\n\n  int getMaxDist(int mask, const vector<vector<int>>& dist, int n) {\n    int maxDist = 0;\n    int edgeCount = 0;\n    int cityCount = 0;\n    for (int u = 0; u < n; ++u) {\n      if ((mask >> u & 1) == 0)  // u is not in the subset.\n        continue;\n      ++cityCount;\n      for (int v = u + 1; v < n; ++v) {\n        if ((mask >> v & 1) == 0)  // v is not in the subset.\n          continue;\n        if (dist[u][v] == 1)  // u and v are connected.\n          ++edgeCount;\n        maxDist = max(maxDist, dist[u][v]);\n      }\n    }\n    return edgeCount == cityCount - 1 ? maxDist : 0;\n  }\n};\n\n```
['C++']