Under construction

Still being built. Things may change

Exciting Travel

Time limit2sMemory limit1024 MB

Summary
Given a tree and several ordered city lists, find the fewest yacht rides needed so each day's trip never visits the same city twice.
Level

Medium7 of 10

Topics
Tree, Greedy, Binary search
Solved
No attempts yet

Problem

After finishing the IODS team selection, you want to travel to a new country to relax. The country contains nn cities, which are connected by n−1n-1 bidirectional roads. There is a unique simple path between any two cities.

In the next mm days, you wish to explore the country. On each day you have set kk cities x_1,x_2,…,x_kx\_1, x\_2, \ldots, x\_{k} that you wish to visit in order. At the beginning of each day, you can choose any city as the starting city of your trip, and then you need to reach city x_1x\_1, then city x_2x\_2, ..., and finally city x_kx\_k to complete your day's travel.

To add to the fun of the trip, you don't want to pass through a city more than once in a day. At any given moment, you can choose to follow a road from this city to another city, or choose to take a yacht to any city.

You want to know, for each day of travel, the minimum number of yacht rides required in order to avoid passing through the same city more than once. Note that each day's travel is independent: a city passed on the previous day can still be passed on the next day.

Input

The first line contains two integers nn and mm (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤m≤5⋅1040 \le m \le 5 \cdot 10^4).

Each of the next n−1n-1 lines contains two integers xx and yy (1≤x,y≤n1 \le x,y \le n, x≠yx \ne y), indicating that there is a bidirectional edge between vertices xx and yy. It is guaranteed that the given graph is connected.

Each of the next mm lines describes queries in the format kx_1x_2…x_kk x\_1 x\_2 \ldots x\_k. It is guaranteed that 1≤x_i≤n1 \le x\_i \le n and x_i≠x_jx\_i \ne x\_j for all 1≤i<j≤k1 \le i < j \le k.

The sum of kk in one test case does not exceed 2⋅1052 \cdot 10^5.

Output

For each day, output a single line containing a single integer: the minimum number of yacht rides.

Hint

The figure corresponds to the first sample test case

The figure corresponds to the second sample test case

Examples2

  1. Example 1

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

    Input
    8 7
    1 2
    1 3
    1 4
    2 5
    2 6
    5 7
    3 8
    1 4
    2 1 7
    3 5 2 4
    4 3 6 1 4
    6 5 3 7 1 2 4
    6 4 8 3 5 6 1
    7 2 8 5 4 6 1 3
    
    Expected output
    0
    0
    0
    1
    4
    3
    5