✅C++ BFS | Easy to Understand Solution
\nclass Solution {\nprivate:\n    vector<vector<int>> graph;\n    unordered_map<int,int> nodeParent;\npublic:\n    int minTime(int n, vector<vector<int>>& edges
```\nclass Solution {\nprivate:\n    vector<vector<int>> graph;\n    unordered_map<int,int> nodeParent;\npublic:\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        graph.assign(n, vector<int>());\n        \n        //Creating The Graph\n        for(auto &it: edges)\n            graph[it.front()].emplace_back(it.back()),\n            graph[it.back()].emplace_back(it.front());\n        \n        \n        //Inserting Parent for all nodes into the nodeParent map....\n        queue<int> nodesQ;\n        {\n            vector<bool> vis(n+1);\n            nodesQ.push(0);\n            vis[0]=true;\n            \n            while(!nodesQ.empty()){\n                int curr = nodesQ.front();\n                nodesQ.pop();\n                \n                for(auto &child: graph[curr])\n                    if(!vis[child]){\n                        vis[child]=true;\n                        nodesQ.push(child);\n                        nodeParent[child]=curr;\n                    }\n            }\n        }\n        \n        //Insert all the nodes having apples into the queue......\n        for(int i=0; i<n; ++i)\n            if(hasApple[i])\n                nodesQ.push(i);\n        \n        \n        //Declare a set for storing {currNode, parent} pair ...\n        //Starting from the Node having the apple and upto the highest level parent..\n        set<pair<int,int>> nodeUtil;\n        while(!nodesQ.empty()){\n            //Current Node having Apple\n            int curr = nodesQ.front();\n            nodesQ.pop();\n            \n            \n            //Parent of this current apple node\n            int parent = nodeParent[curr];\n            \n            //Go upto the highest parent and store the {currentNode, parent} pair\n            for(; parent!=0; curr = parent, parent = nodeParent[parent])\n                nodeUtil.insert({curr, parent});\n            \n            nodeUtil.insert({curr, parent});\n        }\n        \n        \n        //Delete the node pair {0,0} as no cost incuured from the root\n        nodeUtil.erase({0,0});\n        \n        //Size* 2, i.e. parent->node, node->parent, cost incurred two times\n        return nodeUtil.size() * 2;\n    }\n};\n```
['Breadth-First Search', 'Queue', 'C']