Conqueror

Conquer all cities from city 1, where the k-th city you take costs the edge cost plus (k-1)*t, and minimize the total.

Medium7Minimum spanning treeGreedyGraphSortingInterviewNo attempts yetTime limit2sMemory limit256 MB

Problem

The land of Seogang consists of NN cities and MM roads. Every road is bidirectional, and between any two cities there is a path that follows roads. Each road has a cost you pay to use it. The cities are numbered from 11 to NN, and Park Geon, the ruler of city 11, wants to conquer every city.

At the start he holds city 11 only. To conquer a city BB, he must already hold at least one of the cities joined to BB by a road. Once he picks such a city AA, conquering BB costs the cost of the road between AA and BB. Park Geon attempts one city at a time and always succeeds. Each time a city falls, the remaining cities go on alert and the cost of every road rises by tt. A city that has been conquered is never conquered again.

Find the minimum total cost for Park Geon to conquer every city.

Input

The first line contains the number of cities NN, the number of roads MM, and the amount tt by which every road cost rises after each conquest. NN is a natural number at most 1000010000, MM is a natural number at most 3000030000, and tt is a natural number at most 1010.

Each of the next MM lines contains three natural numbers AA, BB, CC describing a road: there is a road of cost CC between city AA and city BB. AA and BB are distinct natural numbers at most NN, and CC is a natural number at most 1000010000. More than one road may join the same pair of cities.

Output

Print the minimum total cost of conquering every city.

Hint

In the first example, city 33, which is joined to city 11, falls first. Conquering it costs 22. After city 33 falls, every road cost rises by 88. The cities held are 11 and 33.

City 44 is joined to city 33, which is already held, so it can be conquered from city 33 at the cost of the road between cities 33 and 44, which is now 1+81+8. The cities held are 11, 33, and 44.

City 22 is also joined to city 33, so it can be conquered too. Conquering it costs the road between cities 22 and 33, which is now 2+8+82+8+8. Every city has now fallen.

The total is 2+(1+8)+(2+8+8)=292 + (1+8) + (2+8+8) = 29.