#P15818. [JOI 2015 Final] JOI 公園

    ID: 17885 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>图论2015最短路JOI(日本)

[JOI 2015 Final] JOI 公園

Problem Description

To prepare for the Olympics to be held in IOI Country in 20XX, it has been decided to renovate JOI Park in IOI Country. There are NN squares in JOI Park, numbered from 11 to NN. There are MM roads connecting these squares, numbered from 11 to MM. Road ii (1≤i≤M1 \le i \le M) bidirectionally connects square AiA_i and square BiB_i, and its length is DiD_i. From any square, you can reach any other square by traveling along some roads.

The renovation plan is as follows: First, choose a non-negative integer XX. Then, between every pair of squares whose distance from square 1 is at most XX (including square 1 itself), connect them with an underground passage. Here, the distance between square ii and square jj is defined as the minimum possible sum of road lengths along a route from square ii to square jj. In the renovation plan, there is an integer CC related to the cost of building underground passages. The total cost to build these underground passages is C×XC \times X.

Next, remove all roads between every pair of squares that are connected by underground passages. Removing roads costs nothing.

Finally, repair all roads that are not removed and remain. The cost to repair a road of length dd is dd.

Before the plan is carried out, there are no underground passages in JOI Park. Find the minimum total cost required to renovate JOI Park.

Task

Given the information about the squares and roads in JOI Park, and the integer related to the underground passage cost, write a program to compute the minimum total cost required to renovate JOI Park.

Input Format

Read the following data from standard input.

  • The first line contains three integers N,M,CN, M, C separated by spaces. This means there are NN squares, MM roads, and the integer related to the underground passage renovation cost is CC.
  • Each of the next MM lines, line ii (1≤i≤M1 \le i \le M), contains three integers Ai,Bi,DiA_i, B_i, D_i separated by spaces. This means road ii connects square AiA_i and square BiB_i, and its length is DiD_i.

Output Format

Output one line to standard output containing one integer, which is the minimum total cost required to renovate JOI Park.

5 5 2
2 3 1
3 1 2
2 4 3
1 2 4
2 5 5
14
5 4 10
1 2 3
2 3 4
3 4 3
4 5 5
15
6 5 2
1 2 2
1 3 4
1 4 3
1 5 1
1 6 5
10

Hint

Sample Explanation 1

In this sample, choose X=3X = 3, and connect every pair of squares whose distance from square 1 is at most 33 (squares 1, 2, and 3) with underground passages. Then the total cost is 2×3+3+5=142 \times 3 + 3 + 5 = 14. This is the minimum value.

Sample Explanation 2

In this sample, the total cost is minimized when X=0X = 0.

Sample Explanation 3

In this sample, the total cost is minimized when choosing X=5X = 5 and connecting every pair of squares with underground passages.

Constraints

All input data satisfy the following conditions:

  • 2≤N≤1000002 \le N \le 100000.
  • 1≤M≤2000001 \le M \le 200000.
  • 1≤C≤1000001 \le C \le 100000.
  • 1≤Ai≤N1 \le A_i \le N (1≤i≤M1 \le i \le M).
  • 1≤Bi≤N1 \le B_i \le N (1≤i≤M1 \le i \le M).
  • Ai≠BiA_i \ne B_i (1≤i≤M1 \le i \le M).
  • (Ai,Bi)≠(Aj,Bj)(A_i, B_i) \ne (A_j, B_j) and (Ai,Bi)≠(Bj,Aj)(A_i, B_i) \ne (B_j, A_j) (1≤i<j≤M1 \le i < j \le M). (That is, there are no multiple edges, and the edges are undirected.)
  • 1≤Di≤1000001 \le D_i \le 100000 (1≤i≤M1 \le i \le M).
  • It is guaranteed that in the given input data, from any square you can reach any other square by traveling along some roads.

Subtasks

Subtask 1 [15 points]

Satisfies the following conditions:

  • N≤100N \le 100.
  • M≤200M \le 200.
  • C≤100C \le 100.
  • Di≤10D_i \le 10 (1≤i≤M1 \le i \le M).

Subtask 2 [45 points]

Satisfies the following conditions:

  • N≤100N \le 100.
  • M≤4000M \le 4000.

Subtask 3 [40 points]

No additional constraints.

Translated by DeepSeek V3.2.

Translated by ChatGPT 5