This page is still under construction.

Parts of this page are still being built. What you see may change.

Network

Time limit1sMemory limit128 MB

Summary
Place the fewest additional servers on internal nodes so every leaf is within distance k of the nearest server.
Level

Medium7 of 10

Topics
Greedy, Tree
Solved
No attempts yet

Problem

Consider a tree network with nn nodes, where the internal nodes are servers and the terminal (leaf) nodes are clients. The nodes are numbered from 11 to nn. Among the servers there is an original server SS that provides a VOD (Video On Demand) service. To guarantee the quality of service for the clients, the distance from each client to the VOD server SS must not exceed a given value kk. The distance between a node uu and a node vv in the tree is the number of edges on the path from uu to vv.

If there is a nonempty subset CC of clients whose distance to SS is greater than kk, then replicas of the VOD system must be placed on some servers so that every client is within distance kk of the nearest VOD server (the original system or a replica).

Given a tree network, the server SS that holds the VOD system, and a positive integer kk, find the minimum number of replicas needed so that every client is within distance kk of the nearest server that holds the original VOD system or a replica.

For example, consider the following tree network.

In this tree the set of clients is {1, 6, 7, 8, 9, 10, 11, 13}, the set of servers is {2, 3, 4, 5, 12, 14}, and the original VOD server is at node 12.

For k=2k = 2, a single VOD server at node 12 does not guarantee the quality of service, because the clients in {6, 7, 8, 9, 10} are farther than kk from it. Therefore one or more replicas are needed. Placing one replica at node 4 makes the distance from every client to the nearest server in {12, 4} at most 22. For this example the minimum number of replicas needed is one.

Input

The input is read from standard input. It consists of TT test cases. The number of test cases TT is given on the first line. The first line of each test case contains an integer nn (3≤n≤1 0003 \le n \le 1\,000), the number of nodes in the tree network. The next line contains two integers ss (1≤s≤n1 \le s \le n) and kk (k≥1k \ge 1), where ss is the VOD server and kk is the distance value for guaranteeing the quality of service. Each of the following n−1n-1 lines contains a pair of nodes describing an edge of the tree network.

Output

Write to standard output. For each test case, print exactly one line containing a single integer: the minimum number of replicas needed.

Examples4

  1. Example 1

    Input
    2
    14
    12 2
    1 2
    2 3
    3 4
    4 5
    5 6
    7 5
    8 5
    4 9
    10 3
    2 12
    12 14
    13 14
    14 11
    14
    3 4
    1 2
    2 3
    3 4
    4 5
    5 6
    7 5
    8 5
    4 9
    10 3
    2 12
    12 14
    13 14
    14 11
    
    Expected output
    1
    0
    
  2. Example 2

    Input
    1
    5
    2 1
    1 2
    2 3
    3 4
    4 5
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    10
    1 1
    1 2
    2 3
    3 4
    1 5
    5 6
    6 7
    1 8
    8 9
    9 10
    
    Expected output
    3
    
  4. Example 4

    Input
    1
    14
    5 2
    1 2
    2 3
    3 4
    4 5
    5 6
    7 5
    8 5
    4 9
    10 3
    2 12
    12 14
    13 14
    14 11
    
    Expected output
    2