EASY || Priority_queue || Dijkstra's Algorithm || C++
\n\n# Code\n\nclass Solution {\npublic:\n    int INF = 1e9;\n\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> matrix(n + 1, ve
\n\n# Code\n```\nclass Solution {\npublic:\n    int INF = 1e9;\n\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> matrix(n + 1, vector<int>(n + 1, INF));\n        vector<vector<pair<int, int>>> adj(n + 1);\n\n        for (int i = 1; i < n; i++) {\n            adj[i].push_back({i + 1, 1});\n            adj[i + 1].push_back({i, 1});\n        }\n\n        adj[x].push_back({y, 1});\n        adj[y].push_back({x, 1});\n\n        for (int i = 1; i <= n; i++) {\n            priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n            pq.push({0, i});\n            matrix[i][i] = 0;\n\n            while (!pq.empty()) {\n                int dist = pq.top().first;\n                int node = pq.top().second;\n                pq.pop();\n\n                if (dist > matrix[i][node]) continue;\n\n                for (auto neighbor : adj[node]) {\n                    int nextNode = neighbor.first;\n                    int edgeWeight = neighbor.second;\n\n                    if (matrix[i][nextNode] > dist + edgeWeight) {\n                        matrix[i][nextNode] = dist + edgeWeight;\n                        pq.push({matrix[i][nextNode], nextNode});\n                    }\n                }\n            }\n        }\n\n        vector<int> ans;\n        for (int k = 1; k <= n; k++) {\n            int count = 0;\n            for (int i = 1; i <= n; i++) {\n                for (int j = 1; j <= n; j++) {\n                    if (i != j && matrix[i][j] == k) {\n                        count++;\n                    }\n                }\n            }\n            ans.push_back(count);\n        }\n\n        return ans;\n    }\n};\n```
['C++']