#Lutece0515. OR Shortest Path
OR Shortest Path
Migrated from Lutece 515 OR Shortest Path
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
OR is a kind of bitwise operator, we defined that as follow: for two number and in binary notation, let . Then for each bit of , we can get its value by check the digit of corresponding position in and . For each digit, , , , . And we simply write this operator as , like ,.
In bitland there is a strange method to calculate the length of a path using OR. If there are edges in a path, and the length of them are , then the length of this path is . Now give you a undirected graph with nodes and edges, find the OR shortest path between and . If and are disconnect, we consider the length between them is .
Input
First line of the input is a single integer (), indicates there are test cases.
For each test case, the first line is four integers (), (), , (,), indicates the number of nodes, the number of egdes, the starting node and the target node respectively. Following lines, each line contains three integers (,,), means there exist an undirected edge between node and node , and the length is .
Output
For each test case, output one line. First ,output Case #C:
, where is the number of test case, from to . Then, you should output a single line contains a single number means the length of the OR shortest path between and or .
Samples
3
4 4 1 4
1 2 1
1 3 2
2 4 2
3 4 1
4 4 1 4
1 2 6
1 3 2
2 4 2
3 4 5
4 2 1 4
1 2 4
3 4 5
Case #1: 3
Case #2: 6
Case #3: -1
Note
For the second case, we choose the path: .
Resources
elfness