Lunar New Year and a Wander
MediumRating 1500CodeforcesHeap / Priority Queue
Approach hintTry it first, then revealHide
Walking back through visited vertices is free, so the next new vertex can be any unvisited neighbour of the visited set. Keep those candidates in a min-heap and always take the smallest. O(m log n).