Python (Simple BFS + DP + BitMasking)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def countSubgraphsForEachDiameter(self, n, edges):\n        def bfs(src,cities):\n            stack, visited, max_dist = [(src,0)], {src}, 0\n\n            while stack:\n                node, dist = stack.pop(0)\n                max_dist = dist\n\n                for neighbor in dict1[node]:\n                    if neighbor not in visited and neighbor in cities:\n                        visited.add(neighbor)\n                        stack.append((neighbor,dist+1))\n\n            return max_dist, visited\n\n\n        def max_distance_two_nodes(state):\n            cities = set()\n\n            for i in range(n):\n                if (state>>i)&1 == 1:\n                    cities.add(i)\n\n            result = 0\n\n            for i in cities:\n                max_dist, visited = bfs(i,cities)\n                if len(visited) < len(cities): return 0\n                result = max(result,max_dist)\n\n            return result \n\n\n        dict1 = defaultdict(list)\n\n        for i,j in edges:\n            dict1[i-1].append(j-1)\n            dict1[j-1].append(i-1)\n\n        ans = [0]*(n-1)\n\n        for j in range(1,2**n):\n            d = max_distance_two_nodes(j)\n            if d > 0: ans[d-1] += 1 \n\n        return ans\n\n        \n\n\n\n\n\n        \n\n        \n\n\n\n\n\n            \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n        \n        \n        \n```
['Python3']