NOI Contest Archive

Archive / 2024 / Final Round — Day 1

The Race for the Throne: A Presidential Quest Across Sri Lanka

Hard · National Olympiad in Informatics Sri Lanka 2024 - Day 1

In the tropical paradise of Sri Lanka, the presidential election season is upon us, and the air is buzzing with excitement and anticipation. Each candidate is vying for the hearts and minds of the people, and grand gestures are the order of the day. From donating properties worth millions to public institutions to promising new infrastructure projects, the candidates are leaving no stone unturned.

However, the current ruler, President Dilan, has a unique and ambitious plan to showcase his commitment to the nation’s prosperity. With the economy showing signs of recovery, President Dilan announces the launch of a new, revolutionary airline service. This service will transport passengers free of charge among a network of newly established airports, each located in a different city. But there’s a catch – the service won’t begin until President Dilan visits each airport and personally inaugurates it.

###The Challenge of the Highways and Airports

President Dilan is based in Colombo, the bustling capital city. To complete his mission, he must travel to each city with an airport and perform the opening ceremony. The cities are connected by a complex web of highways, each with a toll that must be paid. Moreover, once he opens an airport, he can use flights between the already inaugurated airports to minimize the toll costs. The goal is clear: visit all the designated airports while minimizing the total travel cost.

###The Quest

The kingdom has \(n\) cities, each identified by a unique number from \(1\) to \(n\), with Colombo always being city number \(1\). There are \(m\) highways connecting different cities, ensuring there is a path from each city to any other city using these highways. Additionally, \(k\) of these cities have the new airports that need to be inaugurated. Once President Dilan opens an airport, he can use the free airline service to travel between any of the already inaugurated airports. Your task is to help President Dilan plan his journey in the most cost-effective manner.

###Your Mission

Harness the power of algorithms to map out the optimal path for President Dilan. He depends on you to make the most strategic and cost-effective decisions. The future of Sri Lanka’s connectivity lies in your hands!

Input Format

Output Format

Constraints

Limits

Sample Input 0

4 3
1 2 1
2 3 5
2 4 10
3
2 3 4

Sample Output 0

16