#P6527. 「Wdoi-1」幻能采集
「Wdoi-1」幻能采集
Background
Illusory energy is a brand-new kind of energy.
Note: Click "Expand" for a better reading experience.
Problem Description
In a graph , for a vertex set of size , if there exists a vertex numbered such that, taking each vertex in as a start point and as the end point, one can choose paths that do not share multiple edges, then is called the "focus point" of the set .
The map of Gensokyo can be modeled as an edge-weighted unrooted tree with nodes (the length of a path is defined as the sum of the weights of all edges on the path). The sages have placed illusory energy collectors on nodes of the tree.
To make full use of illusory energy, the sages require that for any subset of these nodes with size at least and at most a given constant , an energy hub that is only used to receive illusory energy transmitted by should be set up at every "focus point" of in the tree. Let one such "focus point" be . The cost to build this energy hub is computed as follows:
Here, denotes the shortest distance between the two nodes numbered and .
Since plans may change, the sages have designed multiple schemes for placing the illusory energy collectors, and the constant corresponding to each scheme is not necessarily the same.
Now, for each scheme , the sages want to make queries. In each query, they ask: if we only build all the energy hubs that should be built for node , what is the total cost (the total cost equals the sum of the costs of building each energy hub)? Since Gensokyo has no computers, they have found you, who are skilled in , to help.
Of course, since the answer may be very large, you only need to output the result of the total cost .
Input Format
The first line contains two integers , denoting the number of nodes and a certain parameter.
The next lines each contain three integers , denoting an undirected edge between and with length .
The next line contains an integer , denoting the number of schemes for placing illusory energy collectors.
For each scheme:
The first line contains two integers , denoting the number of illusory energy collectors and the upper bound on the subset size.
The second line contains integers, denoting the nodes where the collectors are placed. It is guaranteed that these integers are pairwise distinct.
The third line contains an integer , denoting the number of queries for this scheme.
The next lines each contain one integer , denoting a query for the total cost of building all hubs that should be built for node .
For some reason, the actual queried value is , where denotes the answer to the previous query. For the first query, . After changing schemes, is not reset to .
Output Format
Output several lines. Each line contains one integer, denoting the answer to the query modulo .
8 0
1 2 1
1 7 1
2 3 3
2 4 1
4 5 1
4 6 2
7 8 1
1
4 2
1 3 5 6
3
1
2
4
0
23
20
20 1
2 1 6
3 1 10
4 1 4
5 4 10
6 2 3
7 1 5
8 4 4
9 6 5
10 8 8
11 2 1
12 7 9
13 6 1
14 8 7
15 5 4
16 10 9
17 12 7
18 4 10
19 11 10
20 13 7
2
6 3
2 16 18 1 8 5
5
19
11
18
8
20
6 3
8 3 17 13 7 20
5
1
15
6
10
6
0
0
0
850
810
0
0
720
0
720
Hint
For of the testdata, , , , .
| Subtask ID | Special Constraints | Score | |||
|---|---|---|---|---|---|
| - | |||||
| - | |||||
This problem uses bundled testing.
Translated by ChatGPT 5