themaskedhero's blog

By themaskedhero, history, 3 years ago, In English,

Hi CF Community:

Today I was solving the problem Farmcraft (http://main.edu.pl/en/archive/oi/21/far). Basically in this problem, you start at the root of a tree, and when you reach a node, you start a timer in that node(except for the root, which only starts when you visit it last). Each node has a time value ti, and a timer in that node ends when it reaches ti. What is the minimum amount of time for all timers to end, if you walk the tree in the optimal way.

My idea was to binary search the minimum time, and then subtract this from each node's ti. Then, this gives the maximum time that you can reach each node. But how should I check if its possible to satisfy all maximum times. Or is there another solution?

 
 
 
 
  • Vote: I like it
  • +4
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

what's the time and memory limit?

»
3 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

Suppose you are at node x. Now you must choose an optimal order of visiting the children of x.

Consider if it has just two children a and b. We have the information of the time it takes traverse the edges of a child's subtree, and the best time of a computer being turned on for a child's subtree (i.e. the 'answer' for that subtree alone). What would be best?

Spoiler

Okay, now we know the best way to choose out of two nodes. How does this apply to more than two nodes?

Suppose we have a proposed solution. Notice that if two adjacent children in the solution order (say a and b) are better to be switched (i.e. the condition inside the spoiler), then we always switch them. Therefore it is optimal to sort by this condition for the entire list.

I'm sure you can work out the final solution with this idea of sorting :)