#Lutece0366. Going back home
Going back home
Migrated from Lutece 366 Going back home
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Finally, finally this semester is over. QiQi plans to go back home.
QiQi lives in a world consist of n cities. He is currently at city S for school and about to go to city D where his home is. QiQi’s world is a little bit different from ours. In his world, one-way road collect two cities and each road is associated with a string. The time QiQi need to travel that road is the length of that string. QiQi doesn’t want to get back home too late because he missed his family so much, but not too early because he really enjoys the scenery along his trip. So he decided to go back home during the period to .(both inclusive). As QiQi is not good at routing, he asks you to help him to come up with a perfect plan for him. You may wonder what perfect means? Because he’s too shy to say it, he lets me tell you that a perfect plan is a route that the strings along this route form a lexicographically smallest one among all legal routes, but it may not be the shortest one.
Input
The first line of the input is an integer (), which stands for the number of test cases you need to solve.
Every test case begins with six integers , , , , , (, , , , ), where is the number of cities, is the number of edges. is the city which QiQi is present in, is the city QiQi tries to reach. , are the earliest and the latest time QiQi wants to reach his destination.
Then lines follow. Each line contains two integers , and a string which is at most letters long(only lowercase latin letters). Means that there is a direct road from to associated with string .().
Output
For every test case, you should output Case #k:
first, where indicates the case number and starts at . Then if it’s impossible to reach city during the period to (both inclusive), output Impossible
, otherwise output the route. See sample for more details.
Samples
2
4 4 0 3 4 4
0 1 abc
0 2 aaaa
1 3 d
2 3 d
2 1 0 1 1 4
0 1 abcde
Case #1: abcd
Case #2: Impossible
Resources
The 9th UESTC Programming Contest Preliminary