Solution
Actually, the path of a car is not unique (go forward to 0 0 0), although this is not clear from the implication of this problem, but there is also no stipulation limits on the path, so you can imagined that the path is arbitrary (the direction is arbitrary, stop or move is arbitrary). for example
0
1
2
3
4 5
for 4 , 5 4, 5 4,5, if using two cars, then the cost is 4 + 4 4 + 4 4+4; but if the car of 4 4 4 turn on 3 3 3 and then to take 5 5 5, it costs 1 + 1 + 1 + 3 1 + 1 + 1 + 3 1+1+1+3, it is better.
But, the latter is also not the best. (you can let the car of 4 4 4 stop at 3 3 3, and then 5 5 5 uses its own car to 3 3 3, then 5 5 5 get off and use the car of 4 4 4 together)
Due to the least distance between a a a and 0 0 0 is the simple-path, so, the path of the car a a a may be this simple-path, but the path of a a a must be this simple-path.
For a number
a
a
a, the size of the subtree which take
a
a
a as its root is
1
+
k
1 + k
1+k (
k
k
k is the count of its sons).
Supposing that these
1
+
k
1+k
1+k are now at
a
a
a, our goal is to take these points to
f
a
fa
fa (the father of
a
a
a), this will cost
(
1
+
k
)
/
L
(1 + k) / L
(1+k)/L (upper round) cars.
So, the answer is the sum of all this number of all points but
0
0
0.