EASY SOLUTION | BFS | SHORTEST DISTANCE BETWEEN NODES
\n\n# Code\n\nclass Solution {\npublic:\n    void solve(int node, vector<vector<int>> &graph, vector<int> &res){\n        queue<pair<int,int>> q;\n        int n
\n\n# Code\n```\nclass Solution {\npublic:\n    void solve(int node, vector<vector<int>> &graph, vector<int> &res){\n        queue<pair<int,int>> q;\n        int n=graph.size();\n        q.push({0,node});\n        res[node]=0;\n\n        while(!q.empty()){\n            int d=q.front().first;\n            int root=q.front().second;\n\n            q.pop();\n\n            for(auto it : graph[root]){\n                int wt=d+1;\n                if(wt<res[it]){\n                    res[it]=wt;\n                    q.push({wt,it});\n                }\n            }\n        }\n    }\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> graph(n+1);\n\n        if(x!=y){\n            graph[x].push_back(y);\n            graph[y].push_back(x);\n        }\n\n        for(int i=1; i<n; i++){\n            graph[i].push_back(i+1);\n            graph[i+1].push_back(i);\n        }\n\n        vector<int> ans(n);\n\n        for(int i=1; i<=n; i++){\n            vector<int> res(n+1,1e9);\n            solve(i,graph,res);\n\n            for(int i=0; i<n+1; i++){\n                if(res[i]==0 || res[i]==1e9) continue;\n\n                ans[res[i]-1]++;\n            }\n\n        }\n\n        return ans;\n    }\n};\n\n```
['Breadth-First Search', 'Graph', 'Queue', 'C++']