Trains the technique from
LeetCode 1443Minimum Time to Collect All Apples in a TreeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A network of n junctions numbered 0 through n - 1 is joined by the pipes pipes, one fewer pipe than there are junctions, with every junction reachable from every other and no loop anywhere. Walking a pipe takes one second, either way.
marked[i] says whether junction i needs visiting.
Start at junction 0, visit every marked junction, and return to junction 0. Return the fewest seconds it takes.
Example 1
Only junction 2 is marked, and reaching it means walking two pipes out and the same two back. The pipe to junction 3 has nothing marked beyond it and is never walked.
Example 2
Both junctions hanging off the start are marked, so each of the two pipes is walked out and back.
Example 3
The one junction is where the walk starts, so it is already visited and nothing needs walking.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def min_time(n: int, pipes: list[list[int]], marked: list) -> int:public int minTime(int n, int[][] pipes, boolean[] marked)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.