C++ || Floyd Warshall || Best approach
Code\ncpp []\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> floyd(n+1,vector<int>(n+1,1e9));\n    
# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> floyd(n+1,vector<int>(n+1,1e9));\n        for(int i=1;i<=n;i++){\n            for(int j=1;j<=n;j++){\n                if(i==j)    floyd[i][j]=0;\n                if(i==j+1 || i+1==j)    floyd[i][j]=1;\n            }\n        }\n        if(x!=y){\n            floyd[x][y]=1;\n            floyd[y][x]=1;\n        }\n        for(int k=1;k<=n;k++){\n            for(int i=1;i<=n;i++){\n                for(int j=1;j<=n;j++){\n                    if(floyd[i][k]+floyd[k][j]<floyd[i][j]){\n                        floyd[i][j]=floyd[i][k]+floyd[k][j];\n                    }\n                }\n            }\n        }\n        vector<int> ans(n+1,0);\n        for(int i=1;i<=n;i++){\n            for(int j=1;j<=n;j++){\n                if(floyd[i][j]>=1 && floyd[i][j]<=n){\n                    int temp=floyd[i][j];\n                    ans[temp]++;\n                }\n            }\n        }\n        vector<int> ans2(ans.begin()+1,ans.end());\n        return ans2;\n    }\n};\n```
['C++']