Banner Home Page Web Contests Problems Ranklist Status Statistics

Treeland Exhibition

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Problem Description


  There are <em>n</em> towns in the treeland and they form a tree, as you may guess, i.e. there is a unique path between every pair of towns. The length of road connecting every pair of adjacent towns is always 1 unit.
</p>
<p>
  You want to hold an exhibition simultaneously on no more than <em>L</em>+1 consecutive towns, i.e. you
  choose two towns <em>u</em> and <em>v</em> of no more than <em>L</em> unit apart, and set up your exhibition in all the
  towns on the unique path from <em>u</em> to <em>v</em>. You want to attract people from all over the treeland to
  your exhibition, so you'd like to minimize the sum of "travelling distance" from every town.
  The "travelling distance" of a town is the distance from that town to its closest exhibition-town.
</p>

<p><b>Input</b></p>

<p>
  There are at most 25 test cases. Each case begins with two integers, <em>n</em> and <em>L</em> (<em>n</em> &lt;= 10000, 0 &lt; <em>L</em> &lt;= 100),
  the number of towns, and the maximal distance of the "endpoint towns" you choose. Next <em>n</em>-1 lines contain
  the descriptions of connections, each with two integers <em>a</em> and <em>b</em>, indicating that town <em>a</em> and town <em>b</em> are
  directly connected (towns are numbered from 0 to <em>n</em>-1). The input ends with <em>n</em> = <em>L</em> = 0.
</p>

<p><b>Output</b></p>

<p>
  For each test case, print the minimal sum of travelling distance.
</p>

<p><b>Sample Input</b></p>

<pre>
3 1
0 1
1 2
4 1
0 1
1 2
2 3
0 0
</pre>

<p><b>Sample Output</b></p>

<pre>
1
2
</pre>
 

Source
The 34th ACM-ICPC Asia Regional 2009 Ningbo Site NIT Cup National Invitation Contest
 

Statistic | Submit | Back