Problem K
Pony-less Express
Howdy, pardner! You’ve been put in charge of mail delivery in these here parts. Your headquarters is in Capital City, and Miss Penelope has asked us to tell all of the local farmsteads about her fashionable doin’s. The roads hereabouts were built so that each farmstead connects to Capital City by only one set of roads, which may connect through multiple other farmsteads. Each road takes exactly one day to travel on a horse.
Each farmstead wants to receive news on their own specific
timetable (so as not to distract the hired hands from their
work), and gets peeved if the delivery misses the desired date,
either early or late. Specifically, each farmstead
Oh, and one more thing: we ain’t payin’ riders to sit idle
at any farmstead, gittin’ into who knows what kind of trouble.
So if news arrives at farmstead
For example, consider the layout of farmsteads shown in
Figure 1 (corresponding to Sample Input
Day: send a horse from Capital City to farmstead
Day: send a horse from Capital City to farmstead and a horse from farmstead to farmstead
Day: send a horse from Capital City to farmstead , a horse from farmstead to farmstead and a horse from farmstead to farmstead
Day: send a horse from farmstead to farmstead
The total anger level, adding up from farmstead
![\includegraphics[scale=0.65]{pony}](/problems/ponylessexpress/file/statement/en/img-0001.png)
Can you help us figure out just how angry people will be in total, so we know what we’re in fer?
Input
The first line of input contains a positive integer
Output
Output the minimum anger level that can be achieved assuming
the first horse leaves Capital City and arrives at a first
farmstead on day
Sample Input 1 | Sample Output 1 |
---|---|
7 3 1 0 3 2 0 2 2 0 2 4 1 1 6 1 3 3 3 4 1 3 |
18 |
Sample Input 2 | Sample Output 2 |
---|---|
3 5 2 2 4 1 0 6 3 1 |
0 |