Floyd–Warshall algorithm
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\nUse the Floyd\u2013Warshall algorithm to get distance between all the p
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\nUse the Floyd\u2013Warshall algorithm to get distance between all the pairs of houses. Go though the distance matrix and update the result array based on the distance between each pair.\n\n(please upvote if it helped)\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 {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        \n        vector<int> res(n+1, 0);\n        \n        vector<int> t(n, INT_MAX);\n        vector<vector<int>> dist(n, t);\n\n        for(int i=0; i<n; ++i)\n            dist[i][i] = 0;\n\n        for(int i=0; i<n-1; ++i)\n        {\n            dist[i][i+1] = 1;\n            dist[i+1][i] = 1;\n        }\n\n        if(x!=y)\n        {\n            dist[x-1][y-1] = 1;\n            dist[y-1][x-1] = 1;\n        }\n\n        for (int k = 0; k < n; ++k) \n            for (int i = 0; i < n; ++i) \n                for (int j = 0; j < n; ++j) \n                    if ( dist[i][k] != INT_MAX && dist[k][j] != INT_MAX && dist[i][k] + dist[k][j] < dist[i][j] ) \n                        dist[i][j] = dist[i][k] + dist[k][j];\n\n\n        for(int i=0; i<n; ++i)\n            for(int j=0; j<n; ++j)\n                res[dist[i][j]]+=1;\n\n\n        res.erase(res.begin());\n        return res;\n        \n    }\n};\n```
['C++']