Potion Farming

First solution:

Take in tree input 
BFS on the tree 
This BFS needs to return a vector of vectors with the traversals you need. 
Vector of vectors of size n: potion_vec 
Vector of vectors of size (min_traversals): traversal_vec2 
For each traversal: 
    For each element in each traversal: 
         in potion_vec, push_back the index of the traversal it's in in traversal_vec,       
         push_back the index of the element     
for (potion in potions) 
    if it has traversals: choose the traversal that has it that has the least other potions potions++; 
    else choose the traversal that has the least potions for the traversal chosen, go thru traversal_vec and delete it from everything in potion_vec

BFS Implementation

Real Solution

So it turns out that I'm insanely stupid.

Since it's a tree, of course you can just figure out the number of traversals through the number of leaves.

The solution to the first subtask is to just greedily pair each leaf with it's closest potion-spawning ancestor.

Last updated