#P9531. [JOIST 2022] 复兴计划 / Reconstruction Project
[JOIST 2022] 复兴计划 / Reconstruction Project
Background
JOISC2022 D4T3.
Problem Description
JOI Town was once a prosperous industrial area. To transport products, many rail tracks and train stations were built there. Although JOI Town has declined, there are still many unused rail tracks and train stations.
There are train stations in JOI Town, numbered . There are remaining rail tracks. The -th track connects stations and in both directions, and its width is . It is guaranteed that you can travel from any station to any other station by passing through some tracks.
You are the mayor of JOI Town. You plan to attract railway companies to use the remaining tracks and stations, so that JOI Town will revive and become a “railway town”.
So, there are railway companies applying to join this reconstruction project. However, different companies’ trains require different track widths. This means you need to rebuild these tracks so that they match the trains of each company.
The track width required by company is . To satisfy company , the following condition must hold:
- Condition: It is possible to travel from any station to any other station using only tracks of width .
To satisfy the condition above, you may rebuild tracks any number of times in the following way:
- Rebuild: Choose a track. You may rebuild it to increase or decrease its width by at a cost of . However, if its width is , you cannot decrease it further.
To determine which companies you can satisfy, you need to find the minimum cost required to satisfy company .
Write a program that, given the information about stations, tracks, and companies, computes the minimum cost required to satisfy company .
Input Format
The first line contains two positive integers , representing the number of train stations and the number of tracks.
The next lines describe the tracks. The -th line contains three positive integers , meaning that the -th track connects these two stations and has width .
Line contains one positive integer , representing the number of railway companies.
The next lines describe the companies. The -th line contains one positive integer , representing the required track width for the -th company’s trains.
Output Format
Output lines. The -th line contains one integer, the minimum cost required to satisfy company .
5 10
1 2 8
1 3 13
1 4 5
1 5 11
1 5 3
2 3 7
2 4 15
3 4 6
3 5 6
4 5 2
6
3
6
8
10
13
17
8
2
5
10
9
21
3 4
1 2 1
1 2 4
2 3 2
2 3 4
4
1
2
3
4
1
1
2
0
10 20
6 7 914727791
1 8 771674531
3 5 632918108
5 9 329296846
1 7 237501112
4 9 303328173
2 6 216298255
2 10 504024991
3 8 158236886
1 10 10176179
8 9 918271145
3 6 217165898
3 6 624543444
4 9 70147274
8 9 976983490
6 9 210108505
2 9 972711062
1 10 564567289
3 7 411395464
4 7 952470985
10
115721165
198969744
356664401
429802521
513343279
610443927
741016686
786597783
898772266
903568946
1121073688
761832468
1026806785
1316097872
1321500065
1445238392
1637513141
1621778548
1733953031
1738749711
Hint
[Sample Explanation #1]
For example, to satisfy company , if you rebuild the tracks as follows, the total cost will be .
- Decrease the width of track by .
- Decrease the width of track by .
- Increase the width of track by .
It can be proven that it is impossible to satisfy company with a cost less than . Therefore, output on the first line.
This sample satisfies the constraints of subtasks .
[Sample Explanation #2]
This sample satisfies the constraints of all subtasks.
[Sample Explanation #3]
This sample satisfies the constraints of subtasks .
[Constraints]
For all testdata:
- .
- .
- .
- .
- .
- .
- It is guaranteed that you can travel from any station to any other station by passing through some tracks.
- .
- .
The additional constraints and scores for subtasks are given in the table below:
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| , | ||
| No additional constraints. |
Translated by ChatGPT 5