#BF0000018. Nghĩa trang ma ám (Haunted Graveyard)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghĩa trang ma ám (Haunted Graveyard)
Haunted Graveyard
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A graveyard is a -by- grid. Enter at and leave at . A normal move to a four-neighboring cell takes one second, but gravestone cells are blocked. Haunted holes force an immediate directed teleport with a signed time change ; you cannot walk out of a hole cell. Reaching the exit ends the walk immediately. If a negative-time cycle can be exploited from the entrance before reaching the exit, print Never. Otherwise print Impossible if the exit is unreachable, or the minimum arrival time.
Input
First line: . Then and gravestone coordinates . Then and lines of for haunted holes. Entry and exit contain neither stones nor holes. Hole origins are unique; neither endpoint contains a gravestone.
Output
Print Never, Impossible, or the minimum time as an integer.
Subtasks
-
Subtask 1 (20 points): ; ; for ; ; no blocked or hole entry/exit, no duplicate hole origins.
-
Subtask 2 (30 points): ; ; for ; ; no blocked or hole entry/exit, no duplicate hole origins.
-
Subtask 3 (50 points): ; ; for ; ; no blocked or hole entry/exit, no duplicate hole origins.
Examples
Input
2 2
0
0
Output
2
Explanation
With no gravestones or holes, two ordinary moves reach the exit, so the minimum time is .