Solution Count Subtrees With Max Distance Between Cities
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    public function countSubgraphsForEachDiameter($n, $edges) {\n        $g = array_fill(0, $n, array_fill(0, $n, 999));\n        \n        foreach ($edges as $e) {\n            $i = $e[0] - 1;\n            $j = $e[1] - 1;\n            $g[$i][$j] = $g[$j][$i] = 1;\n        }\n        \n        for ($k = 0; $k < $n; $k++) {\n            for ($i = 0; $i < $n; $i++) {\n                for ($j = 0; $j < $n; $j++) {\n                    $g[$i][$j] = min($g[$i][$j], $g[$i][$k] + $g[$k][$j]);\n                }\n            }\n        }\n        \n        $ans = array_fill(0, $n - 1, 0);\n        for ($s = 0; $s < (1 << $n); $s++) {\n            $k = substr_count(decbin($s), \'1\');\n            $e = 0;\n            $d = 0;\n            for ($i = 0; $i < $n; $i++) {\n                if ($s & (1 << $i)) {\n                    for ($j = $i + 1; $j < $n; $j++) {\n                        if ($s & (1 << $j)) {\n                            $e += $g[$i][$j] == 1;\n                            $d = max($d, $g[$i][$j]);\n                        }\n                    }\n                }\n            }\n            if ($e == $k - 1 && $d > 0) {\n                $ans[$d - 1]++;\n            }\n        }\n        \n        return $ans;\n    }\n}\n\n```
['PHP']