Family Fares
Time limit3sMemory limit512 MB
Find the minimum total cost for each family member to reach station 1, choosing shortest-path individual tickets or one group ticket priced at g per person.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph, Dynamic programming
- Solved
- No attempts yet
Problem
After a long time apart, your family will gather next year at an idyllic village in the centre of the country. Everyone lives apart, so most will travel by train.
You are in charge of finding the best deal on tickets. Everyone must take an optimal route, meaning they may only travel a route if no other route is shorter.
Two types of ticket are available: individual and group. Every ticket has a start and a destination. Individual tickets are unlimited, and the price equals the shortest distance in kilometres between the two stations.
Group tickets are more complicated. You may buy at most one, and it must be for a fixed list of people. There is no limit to the number of people named, but all of them must be present. The price depends on the number of named persons.

Thick lines are group tickets, and thin lines are individual tickets.
Input
The first line has four integers: (), the number of stations, (), the number of connections, (), the number of family members, and (), the cost per person of a group ticket.
The second line has integers (), meaning family member starts at station .
Each of the next lines has three integers , , and (, , and ), meaning there is a bidirectional connection between stations and with a length of kilometres.
Each pair of distinct stations has at most one direct connection, and every station can be reached from any other station. Station serves the idyllic village.
Output
Output the total amount you must spend so that every family member can travel from their starting station to the idyllic village.