Straight forward Flloyd Warshall | C++ | Java
\n/*************** C++ ***************/\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> grid(n+1, v
```\n/*************** C++ ***************/\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> grid(n+1, vector<int>(n+1, 100000));\n        \n        for(int j = 1; j < n; j++) {\n            grid[j][j+1] = 1;\n            grid[j+1][j] = 1;\n        }\n        grid[x][y] = 1;\n        grid[y][x] = 1;\n        \n        for(int via = 1; via <= n; via++) {\n            \n            for(int i = 1; i <= n; i++) {\n                for(int j = 1; j <= n; j++) {\n                    \n                   grid[i][j] = min(grid[i][j], grid[i][via] + grid[via][j]);\n                    \n                }\n            }\n        }\n        \n        vector<int> result(n);\n        for(int i = 1; i <= n; i++) {\n            for(int j = 1; j <= n; j++) {\n\n                if(i != j) {\n                    int val = grid[i][j];\n                    result[val-1]++;\n                }\n\n            }\n        }\n        \n        return result;\n        \n    }\n};\n```\n\n\n```\n/*************** JAVA ***************/\npublic class Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        int[][] grid = new int[n + 1][n + 1];\n\n        for (int[] row : grid) {\n            Arrays.fill(row, 100000);\n        }\n\n        for (int j = 1; j < n; j++) {\n            grid[j][j + 1] = 1;\n            grid[j + 1][j] = 1;\n        }\n        grid[x][y] = 1;\n        grid[y][x] = 1;\n\n        for (int via = 1; via <= n; via++) {\n            for (int i = 1; i <= n; i++) {\n                for (int j = 1; j <= n; j++) {\n                    grid[i][j] = Math.min(grid[i][j], grid[i][via] + grid[via][j]);\n                }\n            }\n        }\n\n        int[] result = new int[n];\n        for (int i = 1; i <= n; i++) {\n            for (int j = 1; j <= n; j++) {\n                if (i != j) {\n                    int val = grid[i][j];\n                    result[val - 1]++;\n                }\n            }\n        }\n\n        return result;\n    }\n}\n\n\n```
[]