{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)要从(1,1)赶到(n,m),但是...路上常有坎坷,有一种叫做门的生物会在路上拦着![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png),![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)需要找到一种药水来杀死门\n当然,还有一种叫做墙的生物拦着它,![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)不能穿过墙,也没有什么药水可以杀死墙.![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)可以到达吗?"}},{"title":"Input","value":{"format":"MD","content":"输入包含多组数据\n第一行有三个分开的整数,分别是n,m,p.(1\u003c\u003dn,m\u003c\u003d50,0\u003c\u003dp\u003c\u003d10)\n第二行有一个整数k表示生物墙和生物门的数量和.\n接下来k行有五个整数x1,x2,y1,y2,g,表示在x1,x2,y1,y2之间有一个生物\n(|x1-x2|+| y1-y2|\u003d1,0\u003c\u003dg\u003c\u003dp)\n当g\u003d\u003d0时它是一只墙,否则,它是一只型号为g的门\n接下来是一个整数s,表示![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)可以找到的药水数量\n接下来有x,y,g表示在(x,y)中有一个类型g的药水"}},{"title":"Output","value":{"format":"MD","content":"输出![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)最短到达(n,m)的时间\n如果不能到达,输出-1"}},{"title":"Sample Input","value":{"format":"MD","content":"4 4 9\n9\n1 2 1 3 2\n1 2 2 2 0\n2 1 2 2 0\n2 1 3 1 0\n2 3 3 3 0\n2 4 3 4 1\n3 2 3 3 0\n3 3 4 3 0\n4 3 4 4 0\n2\n2 1 2\n4 2 1"}},{"title":"Sample Output","value":{"format":"MD","content":"14"}},{"title":"滑稽","value":{"format":"MD","content":"要是想了解代码怎么打,请访问下面的网站\n[![huaji](https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon25.png)](https://www.baidu.com)"}}]}