
Little IR12660 decided to make a detour in Butea.Task
You are given a weighted binary tree with n nodes and q queries.
For the i-th query (1≤i≤q):
- you are given an integer ki and a set of ki nodes S1,S2,…,Ski;
- you must choose another set of exactly ki nodes T1,T2,…,Tki;
Note that T can also contain nodes from S (or even T=S)
- your goal is to minimize the following value: ∑a=1ki∑b=1kidist(Sa,Tb) where dist(u,v) denotes the length of the shortest path between nodes u and v in the tree.
The first line contains two integers n and q --- the number of nodes and the number of queries.
The next n - 1 lines describe the edges of the tree. On the i-th of these lines, three integers ui, vi, and wi are given, indicating that there is an edge between nodes ui and vi with weight wi.
The next q lines describe the queries. On the i-th of these lines are given:
- an integer ki,
- followed by ki distinct integers representing the nodes S1,S2,…,Ski.
The values written on the same line are separated by a single space.
Output data
The output will contain q lines. On line j (1≤j≤q) output a single integer --- the minimum possible value of the expression corresponding to the j-th query.
Constraints and clarifications
- 1≤n,q≤2⋅105
- 1≤wi≤10 for all 1≤i≤n.
- ∑i=1qki≤2⋅105.
- 1≤Si≤n for all queries.
- It is guaranteed that the given edges form a binary tree (i.e. for a suitable choice of the root node each node has at most 2 children).
| # |
Score |
Constraints |
| 0 |
0 |
Examples |
| 1 |
10 |
n,q≤200,∑i=1qki≤400 |
| 2 |
15 |
n,q≤2000,∑i=1qki≤4000 |
| 3 |
20 |
The tree is a chain (i.e. each node has degree at most 2) |
| 4 |
55 |
No further restrictions. |
Example
stdin
10 5
3 4 8
10 9 2
8 1 1
4 10 4
7 1 2
10 5 5
6 8 9
1 3 8
3 2 5
3 8 2 7
5 6 7 8 10 9
4 2 10 9 3
5 6 8 1 9 4
3 2 1 5
stdout
51
306
128
280
103
Explanation

The tree from the sample input. Bold nodes correspond to the first query..For the first query, picking T={1,8,7} yields a cost of 51:
- From node 1, the cost is
dist(1,7)+dist(1,8)+dist(1,2)=2+1+13=16.
- From node 8, the cost is
dist(8,7)+dist(8,8)+dist(8,2)=3+0+14=17.
- From node 7, the cost is
dist(7,7)+dist(7,8)+dist(7,2)=0+3+15=18.
16+17+18=51.