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

建议使用的浏览器:

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

7406:Percolation

题目描述
SSPUer is studying a system called percolation. We model a percolation system using an n-by-n grid of sites. Each site is either open or blocked. A full site is an open site that can be connected to an open site in the top row via a chain of neighboring (left, right, up, down) open sites. We say the system percolates if there is a full site in the bottom row. In other words, a system percolates if we fill all open sites connected to the top row and that process fills at least one open site on the bottom row.
(For the insulating/metallic materials example, the open sites correspond to metallic materials, so that a system that percolates has a metallic path from top to bottom, with full sites conducting. )
Now, giving you the size of the system n, the number of open site m and the position (i,j) of each open site. The position of the top-left grid is (1,1) and the position of the bottom-right grid is (n,n). Your task is to calculate the sum of full sites and tell whether the system percolates or not.


输入解释
For each test case, the first line contains two integers n, m, representing the size of the system and the number of open site.
There are m lines following, each contains two integer i, j, representing the position (i,j) is an open site. (1 <= i <= j <= n)
n<=500
输出解释
For each test case, output a single line containing an integer and a string, representing the sum of full sites and whether the system percolates, if the system percolates output “YES”, if not output “NO”.
输入样例
2 2
1 1
2 2
输出样例
1 NO
提示

The sample is shown on the picture below, which has 1 full site and the system does not percolate. (position (2,2) is open but not full)


该题目包含在题集 SSPU新生赛

共提交 6

通过率 50.0%
时间上限 内存上限
1000 MS 128 MB