Using floyd warshall method
\n# Code\n\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        int[][]m=new int[n][n];\n        for(int i=0;i<n;i++){\n            
\n# Code\n```\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        int[][]m=new int[n][n];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n               if(i==j+1){\n                m[i][j]=1;\n                m[j][i]=1;\n               }\n               else if(i==j)m[i][j]=0;\n               else m[i][j]=Integer.MAX_VALUE/10;\n            }\n        }\n        m[x-1][y-1]=1;\n        m[y-1][x-1]=1;\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                   \n                   if (m[i][k] + m[k][j]\n                        < m[i][j])\n                       m[i][j]\n                            = m[i][k] + m[k][j];\n                    \n                }\n            }\n        }\n        int[]ans=new int[n];\n         for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n              if(m[i][j]!=Integer.MAX_VALUE&&m[i][j]!=0){\n                ans[m[i][j]-1]++;\n              }\n            }\n        }\n        if(x==y)ans[0]--;\n        return ans;\n    }\n}\n```
['Java']