#P12007. 【MX-X10-T3】[LSOT-4] 全国联赛?
【MX-X10-T3】[LSOT-4] 全国联赛?
Description
The wind ensemble club at Kitauji High School (Kyoto Municipal Kitauji High School) has students numbered from to . Before Taki Noboru's arrival, partnership relationships () had been established. Each partnership indicates that after or performs, the other can complete the coordination within 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 special training plans. The -th plan allows any two members to establish a partnership, achieving coordination in units of time. The disharmony degree is defined as the sum of the minimum error times for all pairs . 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 .
Input Format
- The first line contains two integers and .
- The next lines each contain three integers , describing a partnership.
- If , the last line contains integers .
Output Format
One line containing an integer—the minimal disharmony degree modulo .
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 , the minimum error time is , achieved through the path . The total sum of all minimum error times is . No better valid configuration exists.
Data Range
This problem uses subtasks with bundled testing.
- Subtask 1 (13 pts): .
- Subtask 2 (22 pts): .
- 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): , .
- Subtask 5 (15 pts): All are equal.
- Subtask 6 (13 pts): No additional constraints.
For all data: , , .
Translation by DeepSeek R1
京公网安备 11011102002149号