CCO '20 P3 - Mountains and Valleys
View as PDFCanadian Computing Olympiad: 2020 Day 1, Problem 3
You are planning a long hiking trip through some interesting, but well-known terrain. There are  interesting sites you would like to visit and 
 trails connecting pairs of sites. Each trail has a difficulty level indicated as a positive integer.
The trail system is a bit special, however. There are exactly  trails with difficulty level 1 (these are completely flat trails), and the rest of the trails all have a difficulty level of at least 
 (these are very mountainous trails). (The ceiling of 
, denoted as 
, is the smallest integer greater than or equal to 
.)
Additionally, it is possible to travel between any two sites using only the trails with difficulty level 1.
You would like to visit every site, starting your walk from any site of your choice and finishing at some other site, such that you visit each site at least once and the total sum of difficulty levels is minimum among all walks. Note that walking a trail  times with difficulty level 
 contributes a value of 
 to the sum of difficulty levels.
Input Specification
The first line of input contains two space-separated integers  
 and 
 
.
The next  lines contain three space-separated integers 
, 
, and 
, describing the trail between sites 
 and 
 with difficulty level 
 
. Note that there is at most one trail between every pair of sites, and that 
 or 
.
For 1 of the 25 marks available,  and 
.
For an additional 2 of the 25 marks available,  and 
.
For an additional 2 of the 25 marks available, , 
, and either 
 or 
.
For an additional 6 of the 25 marks available,  and 
.
For an additional 2 of the 25 marks available,  and 
.
For an additional 3 of the 25 marks available,  and 
.
For an additional 5 of the 25 marks available,  and 
.
Output Specification
Output one integer, which is the minimum sum of difficulty levels taken for all trails walked to visit each site once.
Sample Input
9 10
0 1 1
0 2 1
0 3 1
1 4 1
2 5 1
2 6 1
3 7 1
3 8 1
2 4 5
6 7 3
Sample Output
11
Explanation of Output for Sample Input
This is the set of flat trails.
This is the entire set of trails with all the difficulty levels.
This is the entire set of trails, with trails with difficulty level 1 being omitted.
An optimal walk for this set of trails is  with a total cost of 
. There is no way to make a walk that visits all the sites at least once with a lower total difficulty level cost.
Comments