|
||||||||||
Dragon slayerTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2813 Accepted Submission(s): 843 Problem Description Long, long ago, the dragon captured the princess. In order to save the princess, the hero entered the dragon's lair. The dragon's lair is a rectangle area of length $n$ and width $m$. The lower left corner is $(0,0)$ and the upper right corner is $(n,m)$. The position of the hero is $(x_s+0.5,y_s+0.5)$. The position of the dragon is $(x_t+0.5,y_t+0.5)$. There are some horizontal or vertical walls in the area. The hero can move in any direction within the area, but cannot pass through walls, including the ends of walls. The hero wants to go where the dragon is, but may be blocked by walls. Fortunately, heroes have access to special abilities, and each use of a special ability can make a wall disappear forever. Since using special abilities requires a lot of physical strength, the hero wants to know how many times special abilities need to be used at least on the premise of being able to reach the position of the evil dragon? Input The first line contains an integer $T(T \le 10)$ —the number of test cases. The first line of each test case contains 3 integers $n,m,K(1 \le n,m,K \le 15)$ —length and width of rectangular area, number of walls The second line of each test case contains 4 integers $x_s,y_s,x_t,y_t(0 \le x_s,x_t < n,0 \le y_s,y_t < m)$ — the position of the hero and the dragon. The next $K$ lines , each line contains 4 integers $x_1,y_1,x_2,y_2(0 \le x_1,x_2 \le n,0 \le y_1,y_2 \le m)$ — indicates the location of the two endpoints of the wall, ensuring that $x_1=x_2$ or $y_1=y_2$. Output For each test case, a line of output contains an integer representing at least the number of times the special ability was required. Sample Input
Sample Output
Source | ||||||||||
|