John's Gardening Invention (gardening)

1 teams scored 8 points on this task, for a maximum score of 8, an average score of 8 and a median score of 8.

Highlights

  1. L. Scientifico - L. da Vinci, Milano is the institute with the most points (8).
  2. Lombardia is the region with the most points (8).

Statement

John the programmer is burnt out after working in the IT sector for so long, so he started to learn about gardening. The current topic he's focusing on is titled "The watering of plants". John created a watering system (he dubbed it S.T.A.N.C.A.N.E.L.L.I..) which can be modeled as a rooted tree graph, consisting of N junctions (numbered from 0 to N-1) and N-1 pipes. Each pipe connects two different junctions, and it is possible to get from any junction to any other junction through the pipes. There's a main junction where the water is pumped into the system. The layout of the system can be described by N integers: P_0, P_1, …, P_N-1, where P_i=-1 if junction i is the main junction, otherwise there's a pipe connecting junctions i and P_i. Every junction has one of two possible states: open or closed, which can be toggled by rotating a valve at the junction. Initially, junction i is in state S_i. The cost of toggling the state of junction i is C_i...