O(n^2) | Easy Solution | C++ | DP | Floyd Warshall Algorithm
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 {\npublic:\n    void shortest_distance(vector<vector<int>>&matrix) {\n\t\tint n = matrix.size();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (matrix[i][j] == -1) {\n\t\t\t\t\tmatrix[i][j] = 1e9;\n\t\t\t\t}\n\t\t\t\tif (i == j) matrix[i][j] = 0;\n\t\t\t}\n\t\t}\n\n\t\tfor (int k = 0; k < n; k++) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tmatrix[i][j] = min(matrix[i][j],\n\t\t\t\t\t                   matrix[i][k] + matrix[k][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (matrix[i][j] == 1e9) {\n\t\t\t\t\tmatrix[i][j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n    vector<int> countOfPairs(int n, int x, int y) {\n        x--;\n        y--;\n        vector<int>ret;\n        vector<vector<int>>matrix(n,vector<int>(n,-1));\n        if(x!=y){\n            for(int i=0;i<n-1;i++){\n                    matrix[i][i+1]=1;\n                    matrix[i+1][i]=1;\n            }\n            matrix[x][y]=1;\n            matrix[y][x]=1;\n\n            shortest_distance(matrix);\n            \n            vector<int>ans(n+1,0);\n            map<int,int>mp;\n            for(int i=0;i<n;i++){\n                for(int j=0;j<n;j++){\n                    mp[matrix[i][j]]++;\n                }\n            }\n             for(int i=1;i<=n;i++){\n                ans[i]=mp[i];\n            }\n            for(int i=1;i<=n;i++){\n                ret.push_back(ans[i]);\n            }\n            \n        }\n        else{\n            for(int i=0;i<n-1;i++){\n                    matrix[i][i+1]=1;\n                    matrix[i+1][i]=1;\n            }\n            vector<int>ans(n+1,0);\n            map<int,int>mp;\n            shortest_distance(matrix);\n            \n            for (auto row : matrix) {\n            for (auto cell : row) {\n                mp[cell]++;\n            }\n        }\n            \n            for(int i=1;i<=n;i++){\n                ans[i]=mp[i];\n            }\n            ans[0]+=2;\n            for(int i=1;i<=n;i++){\n                // cout<<ans[i]<<" ";\n                ret.push_back(ans[i]);\n            }\n            \n        // return {};\n        }\n        return ret;\n    }\n};\n```
['C++']