class Solution {
public:
map<int, vector<pair<int, int>>> M;
void print(map<int, vector<int>>& G) {
for(auto &a : G) {
cout << a.first << ": ";
for(auto &b : a.second)
cout << b << " ";
cout << endl;
}
}
void printM(map<int, vector<pair<int, int>>>& M) {
for(auto &a : M) {
cout << a.first << ": ";
for(auto &b : a.second) {
cout << "(" << b.first << "," << b.second << ")";
}
cout << endl;
}
}
void bfs( map<int, vector<int>>& graph, int start) {
map<int, bool> visited;
//create a Q of pair of node and dist from start node
queue<pair<int, int>> Q;
Q.push(make_pair(start, 0));
visited[start] = true;
while(!Q.empty()) {
int node = Q.front().first;
int prevDist = Q.front().second;
Q.pop();
for(int i=0; i<graph[node].size(); i++) {
if(!visited[graph[node][i]]) {
visited[graph[node][i]] = true;
Q.push(make_pair(graph[node][i], prevDist+1));
/* In the map, keep storing the pairs and the distance from start node */
M[prevDist+1].push_back(make_pair(start, graph[node][i]));
}
}
}
}
vector<int> countOfPairs(int n, int x, int y) {
map<int, vector<int>> graph;
for(int i=1; i<n; i++) {
graph[i].push_back(i+1);
graph[i+1].push_back(i);
}
graph[x].push_back(y);
graph[y].push_back(x);
vector<int> result;
/* run bfs for all nodes */
for(int i=1; i<=n; i++) {
bfs(graph, i);
}
for(int i=1; i<=n; i++) {
result.push_back(M[i].size());
}
//printM(M);
//print(graph);
return result;
}
};