#P5895. [IOI 2013] dreaming 梦想

[IOI 2013] dreaming 梦想

Problem Description

At the beginning of the world, IOI was still a distant dream.

There are NN ponds where Serpent (the water snake) lives, numbered 0,,N10, \cdots, N - 1, and there are MM undirected paths connecting these ponds. Between any two ponds, there is at most one route (a route consists of one or more paths) connecting them, and some ponds cannot reach each other at all (that is, MN1M \le N - 1). It takes Serpent a fixed number of days to walk along each path, and different paths may take different numbers of days.

Serpent's friend Kangaroo wants to build NM1N - M - 1 new paths so that Serpent can travel between any two ponds. Kangaroo may build a path between any two ponds, and the time for Serpent to travel along each new path is always LL days.

Kangaroo wants to find a way to build the paths such that, after building them, the maximum travel time between any two ponds is as small as possible.

Example

In the figure above, there are 1212 ponds and 88 paths (N=12,M=8N = 12, M = 8). Suppose L=2L = 2, meaning Serpent needs 22 days to travel along any new path. Then Kangaroo can build 33 new paths:

  • between pond 11 and pond 22;
  • between pond 11 and pond 66;
  • between pond 44 and pond 1010.

The figure above shows the final state after building the paths. The longest travel time is from pond 00 to pond 1111, which takes 1818 days. This is the best possible result: no matter how Kangaroo chooses to build the paths, there will always be some pair of ponds for which Serpent needs at least 1818 days to travel from one to the other.

Input Format

  • Line 11: NN is the number of ponds, MM is the number of existing paths, and LL is the time for Serpent to travel along a newly built path.
  • Lines 2,,M+12, \cdots, M + 1: A[i]A[i], B[i]B[i], T[i]T[i]. AA, BB, and TT are three arrays of length MM, representing the two endpoints of each path and the time to travel along it. For example, the ii-th path connects pond A[i1]A[i-1] and pond B[i1]B[i-1], and it takes T[i1]T[i-1] days to travel along this path.

For example, the sample in the statement should be written in the following format:

12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3

Output Format

As described above, output the time required to travel between the two farthest ponds (i.e., the maximum travel time between any two ponds).

12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3

18

Hint

Constraints for 100%100\% of the data: 1N1051 \le N \le 10^5, 0MN10 \le M \le N-1, 0A[i],B[i]N10 \le A[i],B[i] \le N-1, 1T[i]1041 \le T[i] \le 10^4, 1L1041 \le L \le 10^4.

Translated by ChatGPT 5