Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int count = 0;
- void dfs(int node, int parent, vector<vector<pair<int, int>>>& adj) {
- for (auto& [child, sign] : adj[node]) {
- if (child != parent) {
- count += sign;
- dfs(child, node, adj);
- }
- }
- }
- int minReorder(int n, vector<vector<int>>& connections) {
- vector<vector<pair<int, int>>> adj(n);
- for (auto& connection : connections) {
- adj[connection[0]].push_back({connection[1], 1});
- adj[connection[1]].push_back({connection[0], 0});
- }
- dfs(0, -1, adj);
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment