Floyd Warshall + Bitset + BFS
Code\n\nclass Solution {\npublic:\n    static const int MX = (int)20;\n    int fw[MX][MX];\n    vector<int> countSubgraphsForEachDiameter(int n, vector<vector<i
# Code\n```\nclass Solution {\npublic:\n    static const int MX = (int)20;\n    int fw[MX][MX];\n    vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        int LG = 1 << (n);\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                fw[i][j] = (int)1e9;\n            }  \n        }\n        for (auto e : edges) {\n            int u = e[0]-1, v = e[1]-1;\n            fw[u][v] = 1;\n            fw[v][u] = 1;\n        }\n        \n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                for (int k = 0; k < n; k++) {\n                    fw[j][k] = min(fw[j][k], fw[j][i] + fw[i][k]);\n                }\n            }\n        }\n        vector<int> ans(n-1);\n        for (int i = 0; i < LG; i++) {\n            int flag = true;\n            int md = 0;\n            if (__builtin_popcount(i) == 1) continue;\n            for (int j = 0; j < n; j++) {\n                if (i & (1<<j)) {\n                    queue<int> q;\n                    int vis = 0;\n                    q.push(j);\n                    while (!q.empty()) {\n                        int fr = q.front();\n                        q.pop();\n                        if (vis & (1 << fr)) continue;\n                        vis |= 1 << fr;\n                        for (int k = 0; k < n; k++) {\n                            if (i & (1<<k) && fr != k) {\n                                if (fw[fr][k] == 1) q.push(k);\n                            }\n                        }\n                    }\n                    if (i != vis) flag = false;\n                    break;\n                }\n            }\n            if (flag) {\n                for (int j = 0; j < n; j++) {\n                    for (int k = j+1; k < n; k++) {\n                        if ((i & (1<<j)) && (i & (1<<k))) {\n                            md = max(md, fw[j][k]);\n                        }\n                    }\n                }\n                if (md > 0) ans[md-1]++;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']