Santa has gone around the world and delivered to every country around the world on Christmas, except one: North Korea. Unsurprisingly, all the kids in North Korea have been naughty this year; except for Kim Jong Un and his
Each of the
Being the naughty kid genius leader he is, Kim is trying to capture Santa to steal all the toys distribute the wealth. Kim set up a grapple gun pointing up in each of the fireplaces, waiting to grab Santa as soon as he enters the chimney. The grapple gun's projectile will travel along the pipes until it reaches the chimney. Unfortunately, the Soviet era detection systems and wiring are quite out of date and thus take time to give the signal to each of the grapple guns. Specifically, the grapple gun at the
Thankfully, Kim has all his best technicians working on a solution now. Before Santa arrives, Kim's technicians will make
Santa wants to find a path down that will allow him to deliver the greatest number of presents without getting caught with a grapple gun. Santa will instantly fly out of the hotel the moment a grapple gun at or below him fires. Help him find save Christmas by calculating the value after each change Kim's technicians make.
Note: It takes Santa zero time to deliver the presents. However, if Santa arrives at a fireplace just as the grapple gun fires, he will not be able to deliver the present.
Input Specification
The first line contains
Followed by
Followed by
The next line contains
Followed by
Output Specification
After each change, print the answer on its own line.
Subtask | Marks | Additional Constraints |
---|---|---|
1 | 10% | |
2 | 15% | |
3 | 15% | |
4 | 20% | The parent of the |
5 | 40% | No additional constraints. |
Sample Input
5
10 2 10 2 10
0 1
1 2
2 4
1 1
2 6
4
4 5
4 1
2 10
4 10
Sample Output
2
0
0
3
Sample Explanation

Before any changes, the most Santa could deliver is 1 present. After he delivers a present to fireplace #1
, there wouldn't be enough time to deliver to any others. If he tried going to #4
, he would get hooked in by the grapple gun as he arrives.
The first change opens a path for Santa to deliver to #4
, allowing him to deliver 2 presents.
The second change makes the grapple gun at #4
fire very early, thus Santa could not even deliver a single present safely.
The third change delays the firing of #2
significantly, but Santa isn't even able to get to #1
before the grapple gun at #4
fires, so he still can't deliver any presents.
The fourth change delays the firing of #4
significantly, allowing Santa to go all the way to either #3
or #5
to deliver 3 presents.
Comments
Do the grapple gun projectiles take the same amount of time that Santa does to go through each pipe or do they travel instantly?
They travel instantly.
Then does it matter if a grapple gun fires at a fireplace that Santa has already visited?
If a grapple gun fires which affects fireplace i after Santa visits fireplace i, then nothing happens.
The statement is so confusing. I got 120 points assuming and guessing everything. The main point is(and they should bold it): Santa always goes down(there is no path just a line).
Um thats what a path is.
I can't understand various points in question:
Sorry about the delay.
.
Delays are limited at