[Python] BFS
\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        \n        def bfs(a, t):\n            q = deque([(a, 0)])\n        
```\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        \n        def bfs(a, t):\n            q = deque([(a, 0)])\n            v = set()\n            while q:\n                a, n = q.popleft()\n                if a == t:\n                    return n\n                \n                for b in g[a]:\n                    if b not in v:\n                        q.append((b, n + 1))\n                        v.add((b))\n                \n            return float(\'inf\')\n        \n        g = defaultdict(set)\n\n        for i in range(1, n):\n            g[i].add(i + 1)\n            g[i + 1].add(i)\n\n        g[x].add(y)\n        g[y].add(x)\n\n        arr = [0]*n\n        v = set()\n\n        for a in range(1, n + 1):\n            for b in range(1, n + 1):\n                if a == b or (a, b) in v:\n                    continue\n\n                v.add((b, a))\n                arr[bfs(a, b) - 1] += 2\n\n        return arr\n```
['Breadth-First Search', 'Python']