C# Bitmask + DFS  2^N*N
\npublic class Solution {\n    public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n        List<int>[] graph = new List<int>[n];\n        for(in
```\npublic class Solution {\n    public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n        List<int>[] graph = new List<int>[n];\n        for(int i = 0; i < n; i++)\n            graph[i] = new List<int>();\n        foreach(int[] e in edges)\n        {\n            graph[e[0]-1].Add(e[1]-1);\n            graph[e[1]-1].Add(e[0]-1);\n        }\n        \n        int[] res = new int[n-1];\n        for(int mask = 1; mask < 1 << n; mask++)\n        {\n            int x = 0, visited = 0, max = 0;\n            while((mask & 1 << x) == 0)\n                x++;\n            MaxDiameter(x, -1, graph, mask, ref visited, ref max);   \n            if(mask == visited && max > 0)\n                res[max-1]++;\n        }\n        return res;\n    }\n    \n    private int MaxDiameter(int x, int p, List<int>[] graph, int mask, ref int visited, ref int max)\n    {\n        int max1 = 0, max2 = 0;\n        visited |= 1 << x;\n        foreach(int next in graph[x])\n        {\n            if(next == p || (mask & 1 << next) == 0) continue;\n            int d = MaxDiameter(next, x, graph, mask, ref visited, ref max) + 1;\n            if(d > max1)\n            {\n                max2 = max1;\n                max1 = d;\n            }\n            else if (d > max2)\n                max2 = d;\n        }\n        \n        max = Math.Max(max, max1 + max2);\n        return max1;\n    }\n}\n```
[]