#P1332. 血色先锋队
血色先锋队
Description
The legion is an by matrix, and each cell represents a member of the Scarlet Vanguard. An infected person spreads the plague to the four adjacent cells (up, down, left, right) every hour, until everyone is infected. You already know the positions of the infection sources. Your task is to compute the time when each of the Scarlet Vanguard’s lords becomes infected, and report it to the Lich King to enable a targeted strike against the Scarlet Vanguard.
Input Format
Line : Four integers , , , , meaning the legion matrix has rows and columns. There are infection sources, and is the number of lords in the Scarlet Vanguard.
The next lines: Each line has two integers , , indicating an infection source at row , column .
The next lines: Each line has two integers , , indicating a lord at row , column .
Output Format
Lines to : Each line contains one integer, the time when that lord becomes infected. The output order matches the input order. If a person’s position is an infection source, then their infection time is .
5 4 2 3
1 1
5 4
3 3
5 3
2 4
3
1
3
Hint
Explanation for Sample 1
As shown below, the infection times for all people, and the positions of infection sources and lords, are marked.

Constraints
For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5
京公网安备 11011102002149号