C# Solution
\npublic class Solution \n{\n    public int MinTime(int n, int[][] edges, IList<bool> hasApple)\n    {\n        var graph = new Dictionary<int, HashSet<int>>();
```\npublic class Solution \n{\n    public int MinTime(int n, int[][] edges, IList<bool> hasApple)\n    {\n        var graph = new Dictionary<int, HashSet<int>>();\n        for(int i = 0; i < n; i++)\n            graph[i] = new HashSet<int>();\n        foreach(var edge in edges)\n        {\n            int u = edge[0], v = edge[1];\n            graph[u].Add(v);\n            graph[v].Add(u);\n        }\n        \n        return DFS(graph, 0, hasApple, new bool[n])[1];\n    }\n    \n    private int[] DFS(Dictionary<int, HashSet<int>> graph, int current, IList<bool> hasApple, bool[] visited)\n    {\n        int[] result = new int[2];\n        if(hasApple[current]) result[0] = 1;\n        visited[current] = true;\n        foreach(var next in graph[current])\n        {\n            if(!visited[next])\n            {\n                var nextResult = DFS(graph, next, hasApple, visited);\n                if(nextResult[0] == 1)\n                {\n                    result[0] = 1;\n                    result[1] += nextResult[1] + 2;\n                }\n            }\n        }\n        \n        return result;\n    }\n}\n```
[]