Easy BFS Multisource Problem || C++ || Beats 89.9 % users ||
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```cpp []\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n\n        vector<vector<int>> adj(n+1);\n        for(int i =1; i < n; i++){\n            adj[i].push_back(i+1);\n            adj[i+1].push_back(i);\n        }\n        \n        if(x != y){\n            adj[x].push_back(y);\n            adj[y].push_back(x);\n        }\n        vector<int> dist(n, 0);\n\n        for(int i = 1; i <= n; i++){\n\n            queue<int> q;\n            q.push(i);\n            int lvl = 0;\n            vector<bool> visited(n, false);\n            visited[i] = true;\n\n            while(!q.empty()){\n                int size = q.size();\n                lvl++;     \n                while(size--){\n                    int front = q.front();\n                    q.pop();\n\n                    for(auto nbr : adj[front]){\n                        if(!visited[nbr]){\n                        q.push(nbr);\n                        visited[nbr] = true;\n                        }\n                    }\n                }\n                dist[lvl-1] += q.size();   \n            }\n        }\n\n        return dist;\n    }\n};\n```
['Breadth-First Search', 'C++']