#P2083. 找人
找人
Description
Xiao Ming is going to visit a classmate, but he only knows the unit and not the exact room. The unit has floors (). Each floor has rooms ().
Xiao Ming will start searching from some room on the first floor. His search method is special: each time he arrives at a room, if the person there is not his classmate, he will ask that person, then go to the room number (a floor and a room) told by that person. If that room is still not his classmate’s, he continues in the same way until he finds the classmate. Of course, it may be impossible to find the classmate.
His stamina is limited: for each floor he climbs, he spends stamina points. Your task is to compute the minimum stamina needed to find the classmate. If it is impossible to find the classmate, output impossible.
You may choose any starting room on floor .
Input Format
The first line contains five integers , , , , (the classmate lives on floor , room ).
Lines to : each line contains integers. In the -th line, for each from to , the -th and -th integers denote the floor and room given by the person living on floor , room . (For the classmate’s own room , the information is exactly their own room number, i.e., .)
Output Format
Print one integer: the answer. If it is impossible to find the classmate, print impossible.
3 3 2 2 3
1 3 3 3 2 1
2 3 1 1 2 3
1 1 1 2 2 3
2
Hint
Constraints
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号