Just One More Tunnel (Easy)
View as PDFThe MAPS design team is preparing the Olympic fencing venue map. Room is the warm-up room, room
is the final piste, and the team needs the fastest simple route between them before the bout begins.
The venue has rooms and
ordinary corridors. Each corridor connects two different rooms, can be used in both directions, and takes a positive number of seconds to traverse. There is at most one ordinary corridor between any pair of rooms.
Some rooms are marked as shortcut rooms. Between any two different shortcut rooms, MAPS has drawn a hidden referee tunnel that can be used in either direction in exactly seconds. Tunnel times are nonnegative:
is allowed and means that moving through a tunnel takes no time.
The fencer must move from room to room
without visiting any room more than once. Find the minimum possible total time. If no such route exists, output
Impossible.
Input
The first line contains three integers ,
, and
(
,
,
).
The second line contains a binary string of length . Its
-th character is
1 if room is a shortcut room, and
0 otherwise.
Each of the next lines contains three integers
,
, and
(
,
,
), meaning there is an ordinary corridor between rooms
and
that takes
seconds.
It is guaranteed that no ordinary corridor connects a room to itself, and there is at most one ordinary corridor between any two rooms.
Output
Print the minimum possible total time, or Impossible if no valid route exists.
Example 1
Input
3 2 3
101
1 2 2
2 3 2
Output
3
Example 2
Input
4 4 0
0110
1 2 2
2 3 2
3 4 2
1 4 9
Output
4
Example 3
Input
4 2 10
1000
1 2 1
2 3 1
Output
Impossible
Comments