simple bfs solution
\n\n# Code\n\nclass Solution {\npublic:\n    int minReorder(int n, vector<vector<int>>& connections) {\n        vector<vector<pair<int,int>>>adj(n);\n        fo
\n\n# Code\n```\nclass Solution {\npublic:\n    int minReorder(int n, vector<vector<int>>& connections) {\n        vector<vector<pair<int,int>>>adj(n);\n        for(auto x:connections){\n            adj[x[0]].push_back({x[1],1});\n            adj[x[1]].push_back({x[0],0});\n        }\n        queue<int>qu;\n        vector<int>vis(n,-1);\n        qu.push(0);\n        vis[0]=0;\n        int ans=0;\n        while(!qu.empty()){\n            int cur=qu.front();\n            qu.pop();\n            for(auto x: adj[cur]){\n                if(vis[x.first]==-1){\n                    vis[x.first]=vis[cur]+1;\n                    ans+=x.second;\n                    qu.push(x.first);\n                }\n            }\n        }\n        return ans;\n        \n    }\n};\n```
['C++']