Company: Arcesium_16oct
Difficulty: medium
Hydrate the nodes Problem Description There is a tree with n nodes numbered 0 to n - 1 , rooted at node 0 . As usual in computer science, the tree grows upside down: node 0 is at the top and every other node hangs below its parent. An apple grows on every node. The apple on node i has a water level waterLevel[i] : -1 means the apple is almost underhydrated , 0 means it is neither almost underhydrated nor almost overhydrated, 1 means the apple is almost overhydrated . You must pour water on exactly one node v . Pouring on v hydrates every apple in the subtree of v , that is v itself and all of its descendants. After the pour: every hydrated apple that was almost overhydrated ( waterLevel = 1 ) becomes overhydrated and costs overhydratedPenalty cents; every apple anywhere in the tree that was almost underhydrated ( waterLevel = -1 ) and received no water becomes underhydrated and costs underhydratedPenalty cents. No other apple costs anything. In particular, an almost underhydrated apple