eolymp
bolt
Try our new interface for solving problems

Juice

\includegraphics{https://static.e-olymp.com/content/12/125ca1ea31aea8580c42f57a6d18f1306de4ccd2.jpg} In the Favela of Rio de Janeiro there was a flicker of light. After months of careful building, they finally connected the generator to the thousands of extension cords and the slum was illuminated by millions of bright lights... However, the capacity of the extension cords was not enough to meet the energy demands of all the houses in the slum. Thus, the engineers had to carefully select which houses should be powered, and which should not, prior to connecting the power generator. Their idea was to power as many houses as possible, based on the energy demands of each house, and the capacity of the extension cords. More specifically, the generator and each of the houses are represented by nodes, and extension cords are represented by edges between these. Thus, each node gets power from exactly one other node. In addition, each node except the generator node has a non-negative power demand. The generator produces an amount of energy that far surpasses the total capacity of the extension cords connected to it, and can thus be treated as an infinite energy source. Given the same data, find out how many houses the engineers were able to cover the energy demands of. \InputFile The first line of the input contains a single integer \textbf{0} ≤ \textbf{n} ≤ \textbf{1000}, the number of houses in the slum. Then follow \textbf{n} lines in the format \textbf{p_i r_i c_i}, where \textbf{0} ≤ \textbf{p_i} ≤ \textbf{n} is the parent node of house \textbf{i}, \textbf{0} ≤ \textbf{r_i} ≤ \textbf{100} is the energy demand of house \textbf{i} and \textbf{1} ≤ \textbf{c_i} ≤ \textbf{100} is the capacity of the extension cord connecting house \textbf{i} to house \textbf{p_i}. The power generator has index \textbf{0}. \OutputFile Output the maximum number of power requirements that can be met.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3
0 3 2
0 100 100
1 1 1
Çıxış verilənləri #1
2
Mənbə ACM ICPC NCPC 2012, 6th October 2012