Easy simple solution using matrix only
Intuition\n Describe your first thoughts on how to solve this problem. \nsolve using matrix\n\n# Approach\n Describe your approach to solving the problem. \n fi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsolve using matrix\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n firstly i calculate dis from each node and then calculate min dis between every node\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\no(n3)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(n2)\n\n# Code\n```\n#include <vector>\n#include <algorithm>\n#include <cmath>\nusing namespace std;\n\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        // Initialize the distance matrix\n        vector<vector<int>> dis(n + 1, vector<int>(n + 1, 1e8));\n        for (int i = 1; i <= n; ++i) {\n            for (int j = 1; j <= n; ++j) {\n                if (i == j) {\n                    dis[i][j] = 0;\n                } else {\n                    dis[i][j] = abs(i - j);\n                }\n            }\n        }\n        dis[x][y] = 1;\n        dis[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                    if (dis[i][j] > dis[i][k] + dis[k][j]) {\n                        dis[i][j] = dis[i][k] + dis[k][j];\n                    }\n                }\n            }\n        }\n        vector<int> ans(n, 0);\n        for (int i = 1; i <= n; ++i) {\n            for (int j = 1; j <= n; ++j) {\n                int val = dis[i][j];\n                if (val > 0 && val <= n) {\n                    ans[val - 1]++;\n                }\n            }\n        }\n        if(x==y)ans[0]--;\n        return ans;\n    }\n};\n\n```
['C++']