#P5411. Maximizing Communication Delay

    ID: 18643 Type: Default 1000ms 256MiB

Maximizing Communication Delay

Maximizing Communication Delay

We are given a tree with (n) data centers numbered (1,2,\dots,n), connected by (n-1) optical cables. Each cable introduces a delay of (1) unit. The delay between any two data centers equals the sum of delays along the unique path connecting them.

We wish to select some data centers as communication stations such that the delay between any two stations does not exceed (d). Suppose the chosen stations are ({w_1, w_2, \dots, w_k}); the total communication delay is defined as
[ \sum_{1\le i<j\le k} \text{dis}(w_i,w_j), ]
where (\text{dis}(w_i,w_j)) denotes the delay between (w_i) and (w_j).

You are given (q) queries. In each query a data center (u) is fixed as a communication station. Your task is to determine the maximum possible total communication delay achievable by selecting a subset of data centers (which must include (u)) that satisfies the pairwise delay constraint (i.e. for any two selected stations, their delay is at most (d)).

inputFormat

The input begins with a line containing three integers (n), (d) and (q) ((1\le n\le 15,\ 1\le d\le n,\ 1\le q\le n)).

Then follow (n-1) lines, each with two integers (u) and (v), indicating that there is an optical cable connecting data centers (u) and (v).

Finally, there are (q) lines, each containing a single integer (u), representing a query where data center (u) must be included as a communication station.

outputFormat

For each query, output a single line containing the maximum total communication delay achievable under the given constraints.

sample

4 2 2
1 2
2 3
2 4
2
3
9

9

</p>