nyoj 21 three water cups (simulated bfs)

Three water glasses

Time limit: 1000 ms | memory limit: 65535 KB

Difficulty: 4

describe
Give three glasses of different sizes, and only the largest one is full, the other two are empty. The three water cups pour water into each other, and the water cup has no mark, so it can only be calculated according to the given volume of the water cup. Now you are asked to write a program that outputs the minimum number of times the initial state reaches the target state.

input
An integer N (0 < N < 50) in the first row indicates the test data of group N
Next, each group of test data has two lines. The first line gives three integers V1 V2 V3 (V1 > V2 > V3 V1 < 100 V3 > 0), indicating the volume of three water cups.
The second line gives three integers E1 E2 E3 (the volume is less than or equal to the corresponding water cup volume) to represent the final state we need
output
Output the minimum number of pour times of corresponding test data for each line. If the target state output-1 is not reached
sample input

2
6 3 1
4 1 1
9 3 2
7 1 1

sample output

3
-1

Idea: there are six states (three water cups pour water into each other) in each cycle. Each time, select the smaller one from the maximum capacity a[i] that can be reached by the water pouring cup and the maximum capacity v[j]-a[j] that can be filled by the water pouring cup, and then check whether the state d[a[0]][a[1]][a[2]] has been accessed. If not, join the queue, and no matter if it has been visited.