Easy to Understand 2 solutions C++ (Time  Complexity :O(n^2 * 2^15))
Solution 1: bit_mask + DFS:\n\nSince the input is small i.e, 15, we can consider n^2 + (n^2) * (2^15)\n\nThis is pretty straightforward\n\n1. Find the distance 
## Solution 1: bit_mask + DFS:\n\nSince the input is small i.e, 15, we can consider n^2 + (n^2) * (2^15)\n\nThis is pretty straightforward\n\n1. Find the distance from node u to all other nodes (O(n^2) complexity)\n2. After setting the distance between node i and node j for all i and j less than < n. \n\n```cpp\nvector<vector<int>> dist_btw_nodes;\n    // void setSubtree()\nvoid setDist(int par, int root, int d, vector<vector<int>>& edges, vector<bool> &visited) {\n   if (visited[root]){\n       return;\n   }\n    dist_btw_nodes[par][root] = d;\n    dist_btw_nodes[root][par] = d;\n    visited[root] = true; \n    for (int i = 0; i < edges[root].size(); i++) {\n        if (edges[root][i] != par) {\n            setDist(par, edges[root][i], d + 1, edges, visited);\n        }\n    }\n    return;\n}\n```\n\n1. We have two options either to include the node in the sub-tree or not include the node in the sub-tree. Since the input is 15 we can check all the combinations 2^15. \n\n  \n\n```cpp\nvoid dfs(int bit_mask, int index ,int n, vector<int>& ans,vector<int> &vst) {\n        if (index > n)return;\n        int max_dist = 0;\n        int k = __builtin_popcount(bit_mask);\n        int set_of_edges_in_subtree = 0;\n\t\t\t\t// Getting the max distance between each node in the subtree\n\t\t\t\t// set_of_edges_in_subtree to check whether the bit_mask/subtree is a\n\t\t\t\t// valid subtree or not, if the number of edge distance 1 isn\'t \n\t\t\t\t// equal to \'number of nodes -1\' then this bit_mask/subtree ain\'t valid. \n        for (int i = 0; i < n; i++) {\n            if (bit_mask & (1 << i)) {\n                for (int j = i + 1; j < n; j++) {\n                    if (bit_mask & (1<<j)){\n                        set_of_edges_in_subtree += dist_btw_nodes[i][j] == 1;\n                        max_dist = max(max_dist, dist_btw_nodes[i][j]);\n                    }\n                }\n            }\n        }\n        if (max_dist > 0 && set_of_edges_in_subtree == (k - 1) && vst[bit_mask] != 1){\n            ans[max_dist-1] ++;\n        }\n            \n        vst[bit_mask] = 1;\n        dfs(bit_mask ^ (1<<index), index+1, n, ans, vst);\n        dfs(bit_mask, index+1, n, ans, vst);\n    }\n```\n\n```cpp\nvector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> graph(n+1);\n\t\t\t\t// Creating the graph\n        for (int i = 0; i < (n-1); i++){\n            graph[edges[i][0]-1].push_back(edges[i][1]-1);\n            graph[edges[i][1]-1].push_back(edges[i][0]-1);\n        }\n\t\t\n        dist_btw_nodes = vector<vector<int>>(n,vector<int>(n,-1));\n\n        for (int i = 0; i < n; i++) {\n            vector<bool> visited(n, false);\n            setDist(i, i, 0, graph, visited);\n        }\n        vector<int> ans(n-1, 0);\n        vector<int> vst(1<<n,-1);\n        dfs(0, 0, n, ans, vst);\n        return ans;\n    }\n```\n\n## Solution 2: Without using DFS (Looping through all the sub trees)\n\nLooping through all the sub trees i.e, from 0 to 2^15.\n\n```cpp\nvector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> graph(n+1);\n        for (int i = 0; i < (n-1); i++){\n            // cout << edges[i][0]-1 << " " << edges[i][1]-1 << "\\n";\n            graph[edges[i][0]-1].push_back(edges[i][1]-1);\n            graph[edges[i][1]-1].push_back(edges[i][0]-1);\n        }\n        dist_btw_nodes = vector<vector<int>>(n,vector<int>(n,-1));\n\n        for (int i = 0; i < n; i++) {\n            vector<bool> visited(n, false);\n            setDist(i, i, 0, graph, visited);\n        }\n        \n        int max_pos_bit_mask = 1 << n;\n        vector<int> ans(n-1, 0);\n\n        for (int bit_mask = 0; bit_mask <= max_pos_bit_mask; bit_mask++){\n            int num_nodes = __builtin_popcount(bit_mask);\n            int set_of_edges_in_subtree = 0;\n            int max_dist = 0;\n            for (int i = 0; i < n; i++) {\n            if (bit_mask & (1 << i)) {\n                for (int j = i + 1; j < n; j++) {\n                    if (bit_mask & (1<<j)){\n                        set_of_edges_in_subtree += dist_btw_nodes[i][j] == 1;\n                        max_dist = max(max_dist, dist_btw_nodes[i][j]);\n                    }\n                }\n            }\n            }\n            if (max_dist > 0 && set_of_edges_in_subtree == (num_nodes - 1)){\n                ans[max_dist-1] ++;\n            }\n        }\n        return ans;\n    }\n```
['Dynamic Programming', 'Tree', 'Depth-First Search', 'Bitmask']