Landline Telephone Network
The mayor of RMRCity wants to create a secure landline telephone network for emergency use in case of serious disasters when the city is cut off from the outside world. Some pairs of buildings in the city can be directly connected with a wire telephone line and the municipality engineers have prepared an estimate of the cost of connecting any such pair.
The mayor needs your help to find the cheapest network that connects all buildings in the city and satisfies a particular security measure that will be explained shortly. A call from a building to another building may be routed through any simple path in the network (i.e., a path that does not have any repeated building). There are also some insecure buildings that one or more persons with serious criminal records live in. The mayor wants only communications intended for these insecure buildings to reach them. In other words, no communication from any building to any building should pass through any insecure building in the network (where is different from and ).
Input
Consists of a single test case. The first line contains three integers where is the number of buildings, is the number of possible direct connections between a pair of buildings, and is the number of insecure buildings. The buildings are numbered from to . The second line contains distinct integers between and (inclusive), which are the numbers of insecure buildings. Each of the next lines contains three integers and describing one potential direct line, where and are the distinct buildings the line connects, and is the estimate of the cost of connecting these buildings. There is at most one direct link between any two buildings in these lines.
Output
Display the cost of the cheapest network satisfying the security measure if it is possible. Otherwise, print "impossible".