Very Simple Explanation with diagram (just form new edges with weight = 0)
\n\n\n            the basic thing to note here is in this tree, whenever a parent is pointing to the child, that route needs to \n            be inverted\n     
![image](https://assets.leetcode.com/users/images/0bad4901-9049-45ea-be17-c053a91bf519_1629469063.283581.jpeg)\n\n\n            the basic thing to note here is in this tree, whenever a parent is pointing to the child, that route needs to \n            be inverted\n            so we have to make all the roads from children to parent (assuming that 0 is the root)\n            so whenever the edge is from the parent to child, which means we can reach the child, \n\t\t\twe need to invert the edge\n            \n            so what i will do is i will assign a weight u to the original edges \n            and also i will create a reverse edge which will have a weight v\n            \n            so now i will start from the root and keep traversing and sum all the weights \n            at the end the total weight will be total = mu + nv (here i have used m original edges and n edges which i created)\n            also when i use an oringinal edge to reach a child from a parent it means that from that node \n\t\t\tthe edge was pointing to the child, which is want we want to reverse \n            so the answer is the total number of parent to child edges, which is equal to m\n            \n            so i will make u = 1 and v = 0\n```\n\nclass Solution {\npublic:\n    vector<vector<pair<int, int>>> g;\n    int ans = 0;\n    void dfs(int u, int parent) {\n        for(auto &[v, w] : g[u]) {\n            if(v != parent) {\n                ans+=w;\n                dfs(v, u);\n            }\n        }\n    }\n    int minReorder(int n, vector<vector<int>>& edges) {\n        g.resize(n);\n        \n        for(auto e : edges) {\n            g[e[0]].push_back({e[1], 1});\n            g[e[1]].push_back({e[0], 0});\n        }\n        dfs(0, -1);\n        return ans;\n    }\n};\n\nSame Solution Using BFS\n\nclass Solution {\n    public :\n    int minReorder(int n, vector<vector<int>>& connections) {\n        vector<vector<pair<int,int>>> graph(n);\n        for(auto e : connections) {\n            graph[e[0]].push_back({e[1] ,1});\n            graph[e[1]].push_back({e[0], 0});\n        }\n        int ans = 0;\n        queue<pair<int,int>> q;\n        q.push({0,0});\n        vector<bool> vis(n,false);\n        while(!q.empty()) {\n            int cur = q.front().first;\n            q.pop();\n            // int wt = q.front().second;\n            if(vis[cur]) continue;\n            \n            vis[cur] = true;\n            for(auto nbrs : graph[cur]) {\n                if(!vis[nbrs.first]) {\n                    ans+=nbrs.second;\n                    q.push(nbrs);\n                } \n            }\n        }\n        return ans;\n    }\n};\n\n```
[]