Move It, Slowpoke!
문제
Centerville has a bit of a problem. Because of recent road construction many slow-moving vehicles (garbage trucks, delivery trucks, etc) have been rerouted through town. Many of the citizens (or at least this problem contributor) are becoming increasingly upset about being stuck behind these vehicles, especially when they stay on one continuous road for an extended period of time. The town council has recently enacted an ordinance stating that no slow-moving vehicle can stay on any two or more roads considered "continuous" past a distance . The details of the ordinance are the following:
- The ordinance begins with a definition of what a "slow-moving vehicle" is. That's not important for us here (though you know one when you see one).
- The ordinance next lists the ordered pairs of roads in town that are considered "continuous". Slow-moving vehicles are allowed to drive on either road in a pair separately (even if the length of either road is ), but cannot drive on the first road followed immediately by the second road if the total length of the pair is . Note that if the second road of one continuous pair matches the first road of another continuous pair, then the three roads in the two pairs are together considered continuous. In other words, if (say)
ABCis considered continuous andBCDis considered continuous, thenABCDis considered continuous. - The ordinance ends with methods to determine (again, these details are not important to us here).
Obviously the owners of these slow-moving vehicles are a bit perturbed (serves them right I say, but again that's not important to us). While finding the shortest path between two points used to be straight-forward (no pun intended), now it's become a bit of a challenge given the restrictions placed on them---in fact, it may not even be possible to get from one point to another. For example, consider the set of roads in Figure 1. Assume that a slow-moving truck must get from intersection A to intersection D, and that three pairs of roads are considered continuous: A B C; A B E; and B F G. If is (or higher), then the truck can drive A B C D. If is , this route is no longer usable, so the shortest path is now A B E C D (Sample Input 1). If is , then A B E is not longer usable, so the shortest route is now A B F G C D (note that in this case you are allowed to drive from A to B even though the length of that road is ). Finally, if is , then it is impossible for this truck to drive from A to D (Sample Input 2). Note that slow-moving vehicles are unable to perform u-turns without causing even more delays, so, for example, the path A B F B C D is not possible for any value of .
Figure 1: Example road network, used by Sample Inputs 1 and 2.
Given a specification of the road network, two intersections and , and a value for , the owners of the slow-moving vehicles would like to know the shortest distance to travel from intersection to intersection .
입력
Input starts with a line containing 6 integers , where () is the number of intersections in the town (numbered 1 to ), is the number of roads between intersections, () is the number of ordered pairs of roads that are considered as continuous when driven consecutively, () is the longest distance that slow-moving vehicles can stay on a continuous sequence of roads, () is the intersection to travel from, and () is the intersection to travel to. Following this are lines, consisting of three integers , , (, , ) indicating a two-way road of length connects intersections and . There is at most one road between any two intersections. Following this are lines, of the form () indicating that driving on the road from to followed by the road from to is considered as continuous driving. It is guaranteed that there is a road between and and that there is a road between and . Note that this does not mean that the reverse order of driving on those roads is considered continuous driving.
출력
If it is impossible to travel from to output impossible; otherwise output the shortest distance to travel from to .
예제
예제 1
7 8 3 25 1 7 1 2 20 2 3 10 2 4 4 4 3 8 2 5 6 5 6 8 6 3 4 3 7 10 1 2 3 1 2 4 2 5 6
42
예제 2
7 8 3 12 1 7 1 2 20 2 3 10 2 4 4 4 3 8 2 5 6 5 6 8 6 3 4 3 7 10 1 2 3 1 2 4 2 5 6
impossible