There are hand turns and face turns. Every hand soap must use a hand turn, while face soap may use either kind.
If there are fewer than face soaps, print . Otherwise, choose exactly original face soaps for face turns. All remaining soaps use hand turns.
Label a hand-turn vertex and a face-turn vertex . The total label sum is zero.
For a fixed assignment, we need a closed walk whose pickups alternate between the two labels. The tree is connected, so any pickup order can be followed. First we find the cheapest route for fixed labels; then we optimize the assignment.