Python || BFS
Code\n\nfrom queue import Queue\nfrom sortedcontainers import SortedSet\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n    
# Code\n```\nfrom queue import Queue\nfrom sortedcontainers import SortedSet\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        graph = defaultdict(set)\n        self.dist_graph = defaultdict(SortedSet)\n        \n        for i in range(1, n) :\n            graph[i].add(i+1)\n            graph[i+1].add(i)\n\n        graph[x].add(y)\n        graph[y].add(x)\n\n        answer = [0 for _ in range(n)]\n        for k in range(1, n+1) :\n           self.bfsUtil(graph, k)\n        \n        for k in range(1, n+1) :\n            answer[k-1] = len(self.dist_graph[k])\n\n        return answer\n\n\n    def bfsUtil(self, graph, i) :\n        queue = Queue()\n        queue.put((i, 0))\n        visited = set()\n        visited.add(i)\n\n        while not queue.empty() :\n            cell, dist = queue.get()\n\n            for neighbor in graph[cell] :\n                if neighbor not in visited :\n                    queue.put([neighbor, dist + 1])\n                    self.dist_graph[dist+1].add((i, neighbor))\n                    visited.add(neighbor)\n\n\n\n\n```
['Python3']