c++ | easy | short
\n\n# Code\n\nclass Solution {\npublic:\n   vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> g(n, vec
\n\n# Code\n```\nclass Solution {\npublic:\n   vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> g(n, vector<int>(n, 999));\n        for (auto &e : edges) {\n            int i = e[0] - 1;\n            int j = e[1] - 1;\n            g[i][j] = g[j][i] = 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                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);\n                }\n            }\n        }\n        \n        vector<int> ans(n - 1, 0);\n        for (int s = 0; s < (1 << n); s++) {\n            int k = __builtin_popcount(s);\n            int e = 0;\n            int d = 0;\n            for (int i = 0; i < n; i++) if (s & (1 << i)) {\n                for (int j = i + 1; j < n; j++) if (s & (1 << j)) {\n                    e += g[i][j] == 1;\n                    d = max(d, g[i][j]);\n                }\n            }\n            if (e == k - 1 && d > 0) {\n                ans[d - 1]++;\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['C++']