#P9487. 「LAOI-1」小熊游景点
「LAOI-1」小熊游景点
Problem Description
There are attractions on Little Bear’s map, and each attraction has a score .
Between pairs of nodes, there are bidirectional direct bus routes, and each route has a cost .
Now Little Bear is at attraction , and the Commander-in-Chief is at attraction . They must meet at some attraction on the path from to along a simple path, and then along a simple path go together to attraction ( can be any node, and neither person will visit attraction twice).
There are queries. Given , choose such that, under the condition that the total cost paid by Little Bear and the Commander-in-Chief is minimized, the total sum of attraction scores they pass through is maximized. Output this total sum of attraction scores. (That is, the sum of scores of attractions passed by Little Bear the sum of scores of attractions passed by the Commander-in-Chief.)
If an edge is traversed multiple times, its cost is counted multiple times. If an attraction is visited multiple times, its score is counted multiple times.
Input Format
The first line contains two integers , representing the number of attractions and the number of queries.
The next line contains integers. The -th integer represents the weight (score) of the -th attraction.
The next lines each contain three integers , indicating that there is a bidirectional bus route with cost between node and node .
The next lines each contain two integers and , indicating the current attractions of Little Bear and the Commander-in-Chief.
Output Format
For each query, output one integer per line representing the answer.
7 1
1 1 1 1 1 1 1
1 2 3
3 6 -4
2 5 2
1 3 6
2 4 1
3 7 5
4 7
8
10 10
786755 -687509 368192 154769 647117 -713535 337677 913223 -389809 -824004
1 2 -785875
1 3 -77082
1 4 -973070
3 5 -97388
2 6 -112274
3 7 657757
4 8 741733
3 9 5656
4 10 -35190
3 3
3 10
7 3
5 1
2 10
10 10
1 6
7 2
8 9
9 1
971424
-1257332
1309101
3420605
-2313033
-2567048
-2467802
352646
759321
1368370
Hint
Sample Explanation
For the first sample, Little Bear’s map is shown in the figure:

Here . Let .
Little Bear’s path is . The total cost is , and the total attraction score is .
The Commander-in-Chief’s path is . The total cost is , and the total attraction score is .
The total cost paid by both is , and the total attraction score passed is .
It can be proven that, under the condition that the total cost is minimized, this choice maximizes the total attraction score they pass through.
Constraints
This problem uses bundled testdata.
| Subtask | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| Little Bear’s map is a chain | ||||
| None | ||||
For of the data, , , and Little Bear’s map is a tree.
(Since Little Bear can visit attractions, why can’t bus prices and attraction scores be negative?)
Translated by ChatGPT 5