当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5652:India and China Origins

题目描述
A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually himalayas rise up. With that at first the communation started to reduce and eventually died.



Let's assume from my crude drawing that the only way to reaching from India to China or viceversa is through that grid, blue portion is the ocean and people haven't yet invented the ship. and the yellow portion is desert and has ghosts roaming around so people can't travel that way. and the black portions are the location which have mountains and white portions are plateau which are suitable for travelling. moutains are very big to get to the top, height of these mountains is infinite. So if there is mountain between two white portions you can't travel by climbing the mountain.
And at each step people can go to 4 adjacent positions.

Our archeologists have taken sample of each mountain and estimated at which point they rise up at that place. So given the times at which each mountains rised up you have to tell at which time the communication between India and China got completely cut off.
输入解释
There are multi test cases. the first line is a sinle integer $T$ which represents the number of test cases.

For each test case, the first line contains two space seperated integers $N, M$. next $N$ lines consists of strings composed of $0, 1$ characters. $1$ denoting that there's already a mountain at that place, $0$ denoting the plateau. on $N + 2$ line there will be an integer $Q$ denoting the number of mountains that rised up in the order of times. Next $Q$ lines contain $2$ space seperated integers $X, Y$ denoting that at ith year a mountain rised up at location $X, Y$.

$T \leq 10$

$1 \leq N \leq 500$

$1 \leq M \leq 500$

$1 \leq Q \leq N*M$

$0 \leq X < N$

$0 \leq Y < M$
输出解释
Single line at which year the communication got cut off.

print -1 if these two countries still connected in the end.

Hint:



From the picture above, we can see that China and India have no communication since 4th year.
输入样例
1
4 6
011010
000010
100001
001000
7
0 3
1 5
1 3
0 0
1 2
2 4
2 1
输出样例
4
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5652

最后修改于 2020-10-25T23:24:31+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 65536/65536K(Java/Others)