C# bitmap
Check the hints in description\n\n\npublic class Solution {\n    public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n        int[] res=new int[n
Check the hints in description\n\n```\npublic class Solution {\n    public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n        int[] res=new int[n-1];\n        HashSet<int>[]  g=BuildGraph(n,edges);\n        for(int i=1;i<(1<<n);i++){\n            int d=CalculateMaxDistance(n,g,i);\n            if(d==0)\n                continue;\n            res[d-1]++;\n        }    \n        return res;\n    }\n    \n    int CalculateMaxDistance(int n, HashSet<int>[] g, int nodes){\n\n        int root=1;\n        int i=1;\n        for(;root<=n;root++)\n            if((i&nodes)>0)\n                break;\n            else\n                i<<=1;\n        int maxdist=0;\n        dfs(-1,root,g,ref nodes, ref  maxdist);\n\n        return nodes==0 ?  maxdist :0;\n    }\n    \n    int dfs(int parent, int at, HashSet<int>[] g, ref int nodes, ref int maxdist){\n        int d1=0,d2=0;\n        int depth=0;\n        //   Console.WriteLine($"nodes={nodes}  root={root}");\n\n        nodes=nodes^(1<<(at-1));\n        foreach(int to in g[at]){\n\n            int p=(1<<(to-1))&nodes;\n            if(p==0)\n                continue;\n\n            int dist=dfs(at,to,g,ref nodes, ref maxdist);\n            if(dist>=d1){\n                d2=d1;\n                d1=dist;\n            }else if(dist>d2)\n            {\n                d2=dist;\n            }\n            \n            depth=Math.Max(depth,dist);\n            \n        }\n        maxdist=Math.Max(maxdist,d1+d2);\n        return depth+1;\n    }\n    \n    HashSet<int>[] BuildGraph(int n, int[][] edges){\n        HashSet<int>[] g =Enumerable.Range(0,n+1).Select (x=> new HashSet<int>()).ToArray();\n        \n        foreach(int[] e in edges){\n            g[e[0]].Add(e[1]);\n            g[e[1]].Add(e[0]);\n        }\n        \n        return g;\n    }\n}\n```
['Bit Manipulation']