#P9476. [_-0 B] 地铁
[_-0 B] 地铁
Background
City A, the hometown of little , has recently opened a subway.
Problem Description
City A has residential areas . The population of the -th residential area is . There are also bidirectional roads forming a tree. The -th road connects residential areas and . It takes time for a person to walk through this road.
Now the government of City A decides to build one subway line. The subway line is a simple path on the tree. If the path passes through the -th road, then taking the subway through (under) this road only takes time. Also, entering and exiting the subway stations costs a total of time.
It is known that when a person travels from one residential area to another, if the travel path shares at least one common edge with the subway path, then they will definitely choose to take the subway for as much of the trip as possible. If there is no common edge, they will walk the whole way. The problem guarantees that for the -th road, . We consider that the larger the product of the populations of two residential areas is, the more likely people want to move between them.
Now, little wants to know, among all ways to build the subway line, the minimum value of $\sum_{a=1}^{n-1}\sum_{b=a+1}^{n}(s_a \cdot s_b \cdot d_{a,b})$, where denotes the time needed to travel from residential area to (or from to , which is the same).
But he cannot do it, so he comes to ask the all-powerful you for help.
Input Format
The first line contains three integers separated by spaces, representing the subtask id, the number of residential areas, and the time cost for entering and exiting stations.
The next lines each contain one integer , representing the population of each residential area.
The next lines each contain four integers separated by spaces, representing the two endpoints of each road, the walking time, and the subway time.
Output Format
One line with one integer, representing the minimum value required.
The answer may exceed the range of a -bit integer. You may use the __int128 type, whose range is .
The following is an output template for the __int128 type:
#include <bits/stdc++.h>
using namespace std;
__int128 ans;
int main() {
/* Your code here */
string str;
if (!ans) {
str = "0";
} else {
str = "";
while (ans) {
str = ((char)(48 + ans % 10)) + str;
ans /= 10;
}
}
cout << str << endl;
return 0;
}
0 5 0
9
9
3
2
3
1 2 7 6
1 3 8 5
1 4 6 5
2 5 9 9
2262
0 10 86
50
6
84
50
83
67
93
55
93
70
1 2 94 7
1 3 97 4
1 10 98 12
2 4 89 1
2 7 98 1
4 5 99 13
4 6 96 5
5 8 95 5
5 9 97 7
33600416
Hint
Sample explanation:
Before building the subway, it is as shown in the figure below:

One optimal subway plan is to build the subway from to . It is as shown in the figure below (solid lines indicate roads where the subway is built):

From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path does not use the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path does not use the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
From to , the path uses the subway. The required time is , and the contribution to the answer is .
In summary, the answer is .
It can be proven that there is no better subway construction plan.
This problem uses bundled tests and subtask dependencies.
| ID | Score | Property | Dependency | |
|---|---|---|---|---|
| N/A | Sample | None | ||
| None | ||||
| A | None | |||
| B | ||||
| C | ||||
| D | ||||
| None | ||||
Special property A: .
Special property B: .
Special property C: The degree of every node is at most .
Special property D: .
Translated by ChatGPT 5