Tourist Information Points
Time limit1sMemory limit256 MB
Choose minimum-cost towns so every town holds a point or borders one.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Graph
- Solved
- No attempts yet
Problem
King Byteasar wants the sights of Byteotia to draw crowds of tourists who spend a lot of money that eventually reaches the royal treasury. Reality falls short of his dream. The king told his councilor to look into it, and the councilor found that foreigners stay away from Byteotia because its road network is sparse.
Byteotia has towns joined by two-way roads, and every road links two different towns. Some roads run over flyovers or through tunnels. There is no guarantee that every town can be reached from every other town.
The councilor also observed that the current road network allows no long journey. Wherever you start, you cannot visit more than 10 towns without passing through some town twice.
The treasury cannot pay for new roads, so Byteasar decided to build tourist information points (TIPs) instead, staffed by officers who advertise the short trips that are available. For each town there must be a TIP either in that town or in one of the towns linked to it by a road. The cost of building a TIP is known for each town. Find the cheapest way of building TIPs that satisfies the condition.
Input
The first line contains two integers and separated by a single space (, ), the number of towns and the number of roads in Byteotia. The towns are numbered from 1 to .
The second line contains integers separated by single spaces (), where is the cost of building a TIP in town .
Each of the next lines describes one road. The -th of these lines contains two integers and separated by a single space (), which means that towns and are linked by a road. There is at most one road between any pair of towns.
In tests worth 20% of the total score, holds.
Output
Print one integer on a single line: the total cost of building all the TIPs.
Hint
In the first example the cheapest choice is to build TIPs in towns 1, 5, and 6, at a cost of .
