BFS Brute Force Python
\n# Code\n\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        \n        adj = defaultdict(list)\n        for i in range
\n# Code\n```\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        \n        adj = defaultdict(list)\n        for i in range(n-1):\n            adj[i].append(i+1)\n            adj[i+1].append(i)\n\n        adj[x-1].append(y-1)\n        adj[y-1].append(x-1)\n        \n        def bfs(start, end):\n            q = deque([(start, 0)])\n            vis = set([start])\n            \n            while q:\n                node, dis = q.popleft()\n                if node == end:\n                    return dis\n\n                for nei in adj[node]:\n                    if nei not in vis:\n                        vis.add(nei)\n                        q.append((nei, dis+1))\n                \n            return -1\n        \n        store = []\n        for i in range(n):\n            for j in range(i+1,n):\n                store.append(bfs(i, j))\n\n        c = dict(sorted(Counter(store).items(), key=lambda x:x[0]))\n        res = list(c.values())\n        res = [x*2 for x in res]\n\n        return res + [0] * (n - len(res))\n\n```
['Python3']