Solution Usin Djisktra
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    vector<int> dj(int &n, vector<vector<int>> &houses, int &src){\n\n        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n        vector<int> dist(n, INT_MAX);\n\n        pq.push({ 0, src });\n        dist[src] = 0;\n\n        while(!pq.empty()){\n\n            auto [distance, node] = pq.top();\n            pq.pop(); \n         \n            for(auto adjHouse : houses[node]){\n                if(1 + distance < dist[adjHouse]){\n                    dist[adjHouse] = 1 + distance;\n                    pq.push({ 1 + distance,  adjHouse });\n                }\n            }\n\n        }\n     \n        return dist;\n    }\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n\n        vector<vector<int>> houses(n);\n        if(x!=y){\n            houses[x-1].push_back(y-1);\n            houses[y-1].push_back(x-1);\n        }\n        for(int i = 0; i < n-1; i++){\n            houses[i].push_back(i+1);\n            houses[i+1].push_back(i);\n        }\n\n    \n        vector<int> ans(n, 0);\n        for(int i = 0; i < n; i++){\n           vector<int> dist = dj(n, houses, i);\n            for(int i = 0; i < n; i++) {\n                if(dist[i]!=INT_MAX && dist[i]!=0){\n                    ans[dist[i]-1]++;\n                }\n            }\n        }   \n     \n        return ans;\n    }\n};\n```
['C++']