## Wesley's Anger Contest 5 Problem 7 - Acorn Delivery System

View as PDF

Points: 30 (partial)
Time limit: 2.0s
Memory limit: 128M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The squirrel nation is setting up an acorn delivery system. There are squirrels numbered from to and each squirrel has a single acorn that they want to deliver to the head squirrel (who is squirrel number ). Specifically, they have designed a system where squirrel will always pass their acorn, and any acorns they receive from other squirrels, to a single squirrel where (with the exception of the head squirrel who will never pass an acorn to anyone).

The squirrels have scattered themselves randomly around their nation, independent of who they pass their acorns to, with the squirrel being located at the point . The additional cost of passing an acorn from squirrel to squirrel is equal to the euclidean distance squared between their locations . In addition, if squirrel receives an acorn (including the head squirrel), an additional cost of , chosen randomly and independent of who any squirrel pass their acorns to, is added.

The acorn originating from each squirrel will pass through a number of squirrels before reaching the head squirrel. In order to minimize the cost, for each acorn, you can choose for it to skip over a subset of the squirrels and move directly to the next unskipped squirrel, without modifying the original order. Of course, you cannot skip the head squirrel as they will be receiving the acorn, or the originating squirrel. For each squirrel, can you determine the minimum cost to deliver their acorn to the head squirrel?

For this problem, Python users are recommended to use PYPY over CPython.

#### Constraints

For this problem, NONE of the samples will appear in the actual test cases. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.

for all
for all
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
for all

##### Subtask 1 [8%]

is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.

##### Subtask 2 [12%]

is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.

##### Subtask 3 [6%]

is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
for all

##### Subtask 4 [4%]

is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.

##### Subtask 5 [16%]

for all
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
for all

##### Subtask 6 [15%]

for all
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.

##### Subtask 7 [17%]

is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
for all

##### Subtask 8 [22%]

is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.
is selected uniformly at random from the range for all , independent of who any squirrel passes their acorns to.

#### Input Specification

The first line of input contains a single integer , representing the number of squirrels in the squirrel nation.

The next lines describe the squirrels. Each contain integers, , , , , indicating that the squirrel is located at , incurs an additional cost of for every acorn that the squirrel receives, and passes their acorn to squirrel in the current system. Only input where is allowed, which indicates that the head squirrel will not pass the acorn to any other squirrel.

#### Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output lines. The line should contain a single integer equal to the minimum cost to deliver the squirrel's acorn to the head squirrel after skipping over a subset of the original squirrel.

#### Sample Input 1

5
0 1 3 2
0 3 1 3
0 7 2 4
0 5 10 5
0 4 3 0

#### Sample Output 1

9
4
12
4
0

#### Sample Explanation 1

Squirrel can pass their acorn to squirrel , who can then pass the acorn to squirrel for a cost of .
Squirrel can pass their acorn to squirrel (skipping squirrels and ) for a cost of .
Squirrel can pass their acorn to squirrel (skipping squirrel ) for a cost of .
Squirrel can pass their acorn to squirrel for a cost of .
Squirrel does not need to pass their acorn to anyone else, and thus incurs a cost of .

#### Sample Input 2

5
0 7 8 2
0 1 5 5
0 9 2 4
0 8 4 5
0 5 10 0

#### Sample Output 2

14
26
24
19
0

#### Sample Input 3

4
1 2 2 2
2 6 3 3
4 3 10 4
5 7 4 0

#### Sample Output 3

34
14
21
0

#### Sample Input 4

6
10 4 2 2
8 6 1 6
1 2 3 4
8 9 4 5
3 2 9 6
6 7 10 0

#### Sample Output 4

24
15
57
18
44
0