☕ Java solution
\n\n\njava []\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        int[][] g = new int[n + 1][n + 1];\n        for (int[] r : g) Arr
\n\n![Screenshot_1.png](https://assets.leetcode.com/users/images/9250a35f-f44f-40c4-b625-fcb0e1fd706b_1729014777.6492732.png)\n```java []\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        int[][] g = new int[n + 1][n + 1];\n        for (int[] r : g) Arrays.fill(r, 100000);\n        for (int i = 1; i < n; i++) {\n            g[i][i + 1] = g[i + 1][i] = 1;\n        }\n        g[x][y] = g[y][x] = 1;\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                    g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);\n        int[] r = new int[n];\n        for (int i = 1; i <= n; i++)\n            for (int j = 1; j <= n; j++)\n                if (i != j) r[g[i][j] - 1]++;\n        return r;\n    }\n}\n```
['Java']