#P12007. 【MX-X10-T3】[LSOT-4] 全国联赛?

    ID: 11892 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心树论构造树的重心梦熊比赛

【MX-X10-T3】[LSOT-4] 全国联赛?

Description

The wind ensemble club at Kitauji High School (Kyoto Municipal Kitauji High School) has nn students numbered from 11 to nn. Before Taki Noboru's arrival, mm partnership relationships (0mn10 \le m \le n - 1) had been established. Each partnership u,v,wu, v, w indicates that after uu or vv performs, the other can complete the coordination within ww units of time. If two students have no direct partnership, they can still coordinate indirectly through multiple partnerships, with the total error time being the sum of all intermediate coordination times.

The current club is as disorganized as a pile of scattered sand! To address this, Taki Noboru has nm1n - m - 1 special training plans. The ii-th plan allows any two members to establish a partnership, achieving coordination in aia_i units of time. The disharmony degree is defined as the sum of the minimum error times for all pairs 1x<yn1 \le x < y \le n. If any pair cannot coordinate in the end, the configuration is considered invalid. To reach the national competition, Taki wants to minimize the disharmony degree.

Calculate the optimal disharmony degree for Taki. The data guarantees at least one valid configuration. Since the result might be large, output the disharmony degree modulo 109+710^9 + 7.

Input Format

  • The first line contains two integers nn and mm.
  • The next mm lines each contain three integers u,v,wu, v, w, describing a partnership.
  • If nm1>0n - m - 1 > 0, the last line contains nm1n - m - 1 integers a1,,anm1a_1, \ldots, a_{n - m - 1}.

Output Format

One line containing an integer—the minimal disharmony degree modulo 109+710^9 + 7.

7 3
1 2 1
3 5 3
3 7 2
1 2 3

76

14 9
8 9 539682
14 4 470495
10 7 265900
14 5 234094
1 9 255217
7 1 559336
7 6 883781
7 13 679978
11 1 598746
433139 142690 902471 766101

108274449

Hint

Sample Explanation #1

The initial partnerships form the structure shown in:

The optimal training adds partnerships as shown in:

For pair (1,7)(1,7), the minimum error time is 44, achieved through the path (1,2)(2,3)(3,7)(1,2) \rightarrow (2,3) \rightarrow (3,7). The total sum of all minimum error times is 7676. No better valid configuration exists.

Data Range

This problem uses subtasks with bundled testing.

  • Subtask 1 (13 pts): n6n \le 6.
  • Subtask 2 (22 pts): n2000n \le 2000.
  • Subtask 3 (18 pts): Before adding new partnerships, any pair of coordinating members can connect via at most one intermediate member.
  • Subtask 4 (19 pts): ai=0a_i = 0, w=1w = 1.
  • Subtask 5 (15 pts): All aia_i are equal.
  • Subtask 6 (13 pts): No additional constraints.

For all data: 0m<n1060 \le m < n \le 10^6, 0ai,w1060 \le a_i, w \le 10^6, 1u,vn1 \le u, v \le n.

Translation by DeepSeek R1