Just One More Tunnel (Easy)
The MAPS design team is preparing the Olympic fencing venue map. Room 1 is the warm-up room, room n is the final piste, and the team needs the fastest simple route between them before the bout begins.
The venue has n rooms and m 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 t seconds. Tunnel times are nonnegative: t=0 is allowed and means that moving through a tunnel takes no time.
The fencer must move from room 1 to room n 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 n, m, and t (2≤n≤103, 1≤m≤103, 0≤t≤106).
The second line contains a binary string of length n. Its i-th character is 1 if room i is a shortcut room, and 0 otherwise.
Each of the next m lines contains three integers ui, vi, and wi (1≤ui,vi≤n, ui=vi, 1≤wi≤106), meaning there is an ordinary corridor between rooms ui and vi that takes wi 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
3 2 3
101
1 2 2
2 3 2
3
Example 2
4 4 0
0110
1 2 2
2 3 2
3 4 2
1 4 9
4
Example 3
4 2 10
1000
1 2 1
2 3 1
Impossible
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.