National Team (IOI2017) Tsinghua training - soda

National Team (IOI2017) Tsinghua training - soda

Questions Description:
Taurus came to a soda-rich country travel.

There are on this country's map n
cities, connected with n-1 road between these cities, between any two cities, there is a path connection. Production of these cities there are many different flavors of soft drinks, when passing the road i, wi beef will drink soda. Taurus is very fond of soft drinks, but excessive drinking soda is harmful to health, so he hopes this time he traveled, the average daily amount of soda drink as close as possible given a positive integer k.

Meanwhile, beef hope his travel plans as much as possible interesting, Taurus will first select a city as a starting point, and then by road every day, have not been to visit a city, a final choice in a city end of the trip.

Taurus also busy to drink Coke, he wants you to help him devise a plan to travel, meet every day | daily average drink soda -k |
value as small as possible, you tell him this minimum.

Entry

The first line of two positive integers n, k.

Next, n-1
lines, each line three positive integers ui, vi, wi, wi denotes have a length of between cities and urban ui vi

Road links.

Two adjacent rows are the same integer separated by a space.

Export

A line integer representing | average daily soda drink -k | minimum value of the integer part, i.e. you simply rounded down and the minimum value can be output.

Sample input

5 21
1 2 9
1 3 27
1 4 3
1 5 12

Sample Output

1

solution:

Simple Plan & score points partition
do not know why write so much on the test constant, and wrote again finished the run fast (fog

See minimize the average, you should try fraction of planning, which is half the answer practice
and on a large scale because of the content processing chain, should point to think of divide and conquer
to consider the question how to do this
read length of time to put all length minus k, so that finally find out the average chain length is one answer to
the set point when a partition subtree and one strand of such a two information (a, B)
a represents the point of partition roots from the true
depth of the root of the point B indicates the partition
when half mid, combined two strands (A1, B1) (A2, B2) has:
\ [-mid <\ FRAC {} A2 {A1 + B1 + B2} <mid \]

Guess you like

Origin www.cnblogs.com/heanda/p/12347042.html