Floyd-Warshall || Bitmask || Explanation and Solution [C++]
*This problem is quite easy, just take two steps:\n+ First, I will find the length of any two vertices using the Floyd-Warshall algorithm.\n+ Browse all aggrega
****This problem is quite easy, just take two steps:****\n+ First, I will find the length of any two vertices using the Floyd-Warshall algorithm.\n+ Browse all aggregations using Bitmask.\n\n****Vote if you think it\'s good****\n\n****Here is my C++ code you can refer to****\n\n```\nclass Solution {\npublic:\n    vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        const int oo = n;\n        vector<vector<int>> dp(n, vector<int>(n, oo));\n        \n        for (vector<int> edge : edges) {\n            int u = edge[0] - 1;\n            int v = edge[1] - 1;\n            dp[u][v] = dp[v][u] = 1;\n        }\n        \n        for (int k = 0; k < n; ++k) {\n            for (int u = 0; u < n; ++u) {\n                for (int v = 0; v < n; ++v) {\n                    if (u == v or k == v or k == u) {\n                        continue;\n                    }\n                    dp[u][v] = min(dp[u][v], dp[u][k] + dp[k][v]);\n                }\n            }\n        }\n        \n        vector<int> ans(n - 1);\n        \n        for (int mask = 1; mask < (1 << n); ++mask) {\n            int max_dist = 0;\n            int cnt_vertex = 0, cnt_edge = 0;\n            \n            for (int i = 0; i < n; ++i) {\n                if ((mask & (1 << i)) == 0) {\n                    continue;\n                }\n                cnt_vertex++;\n                for (int j = i + 1; j < n; ++j) {\n                    if ((mask & (1 << j)) == 0) {\n                        continue;\n                    }\n                    cnt_edge += dp[i][j] == 1;\n                    max_dist = max(max_dist, dp[i][j]);\n                }\n            }\n            \n            if (max_dist != 0 and cnt_edge == cnt_vertex - 1) {\n                ans[max_dist - 1]++;\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['C', 'Bitmask']