C# DFS
Approach\nTreat the graph as undirected. Start a dfs from the root, if you come across an edge in the forward direction, you need to reverse the edge.\n\n# Comp
# Approach\nTreat the graph as undirected. Start a dfs from the root, if you come across an edge in the forward direction, you need to reverse the edge.\n\n# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\npublic class Solution\n{\n    private readonly Dictionary<int, List<(int city, bool direction)>> _graph = new();\n    private readonly HashSet<int> _visited = new();\n    private int _result;\n\n    public int MinReorder(int n, int[][] connections)\n    {\n        foreach (var connection in connections)\n        {\n            var cityA = connection[0];\n            var cityB = connection[1];\n\n            _graph[cityA] = _graph.GetValueOrDefault(cityA, new List<(int, bool)>());\n            _graph[cityA].Add((cityB, true));\n\n            _graph[cityB] = _graph.GetValueOrDefault(cityB, new List<(int, bool)>());\n            _graph[cityB].Add((cityA, false));\n        }\n        \n        dfs(0);\n\n        return _result;\n    }\n\n    private void dfs(int city)\n    {\n        _visited.Add(city);\n\n        foreach (var (node, direction) in _graph[city])\n        {\n            if (_visited.Contains(node)) continue;\n\n            if (direction)\n            {\n                ++_result;\n            }\n\n            dfs(node);\n        }\n    }\n}\n```
['C#']