Floyd-Warshall Algorithm
\n# Code\ncpp []\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> dis(n, vector<int> (n, 1e9));\n   
\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> dis(n, vector<int> (n, 1e9));\n        for(int i=0; i<n; i++){\n            dis[i][i]=0;\n        }\n        for(int i=0; i<n-1; i++){\n            dis[i][i+1]=1;\n            dis[i+1][i]=1;\n        }\n        if(x!= y){\n            dis[x-1][y-1]=1;\n            dis[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(dis[i][k] !=1e9 && dis[k][j]!=1e9){\n                        dis[i][j]=min(dis[i][j], dis[i][k] +dis[k][j]);\n                    }\n                }\n            }\n        }\n\n        vector<int> ans(n+1, 0);\n        for(int i=0; i<n; i++){\n            for(int j=0; j<n; j++){\n                ans[dis[i][j]]+=1;\n            }\n        }\n\n        ans.erase(ans.begin());\n        return ans;\n    }\n};\n```
['C++']