#P3821. Isaac
Isaac
Description
Determine whether Ju Runguo can pass the final level without taking damage under the above conditions. If he can, output the minimum required health for Isaac under Ju Runguo’s control; otherwise, output 'IMP0SSBLE!!'.
Input Format
The first line contains five numbers , representing that there are rooms in total, pairs of adjacent rooms together with the required health to traverse them, the start is , the finish is , and Isaac must arrive exactly at time .
Each of the next lines contains three numbers , meaning that room and room are adjacent, and the required health to traverse between the two rooms in both directions is .
The next line contains a single number , the number of monsters.
Then follow data blocks, each describing one monster’s roaming pattern.
In each block, the first number is the number of rooms in the monster’s roaming cycle, followed by room IDs that indicate that starting from time , the monster will move from the first room in order and periodically repeat the sequence.
Output Format
Output a single line: the minimum required health for Isaac under Ju Runguo’s control, or 'IMP0SSBLE!!'.
2 1 1 2 1
1 2 1
0
1
2 1 1 2 1
1 2 2
0
2
2 1 1 2 10000001
1 2 2
0
2
2 1 1 2 10000001
1 2 2
1
2
2 1
2
Hint
There are groups of testdata.
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , , , , .
All inputs are within the range of int.
All numbers are positive. There may be multiple edges; if an edge is given multiple times, the weight of its last occurrence prevails.
Translated by ChatGPT 5
京公网安备 11011102002149号