CF193A.Cutting Figure
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not connected.
A set of painted squares is called connected, if for every two squares a and b from this set there is a sequence of squares from the set, beginning in a and ending in b, such that in this sequence any square, except for the last one, shares a common side with the square that follows next in the sequence. An empty set and a set consisting of exactly one square are connected by definition.
你得到了一张 n×m 的方格纸,其中部分方格已被涂色。记所有被涂色的方格构成的集合为 A,且集合 A 是连通的。你的任务是:求出从集合 A 中最少需要删除多少个方格,才能使其变为不连通。
一个被涂色方格的集合被称为连通的,当且仅当对该集合中任意两个方格 a 和 b,均存在该集合中的一对方格序列,其起点为 a、终点为 b,且该序列中除最后一个方格外,每个方格均与它后一个方格有一条公共边。按定义,空集以及仅含一个方格的集合均为连通的。
输入格式
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the sizes of the sheet of paper.
Each of the next n lines contains m characters — the description of the sheet of paper: the j-th character of the i-th line equals either "#", if the corresponding square is painted (belongs to set A), or equals "." if the corresponding square is not painted (does not belong to set A). It is guaranteed that the set of all painted squares A is connected and isn't empty.
第一行输入包含两个以空格分隔的整数 n 和 m(1 ≤ n, m ≤ 50)——表示纸张的尺寸。
接下来的 n 行中,每行包含 m 个字符,用于描述该纸张:第 i 行的第 j 个字符为 #,表示对应方格已被涂色(属于集合 A);为 .,则表示对应方格未被涂色(不属于集合 A)。保证所有已涂色方格构成的集合 A 是连通的,且非空。
输出格式
On the first line print the minimum number of squares that need to be deleted to make set A not connected. If it is impossible, print -1.
第一行输出使集合 A 不连通所需删除的正方形的最小数量。如果不可能,输出 -1。
输入输出样例
输入#1
5 4 #### #..# #..# #..# ####
输出#1
2
输入#2
5 5 ##### #...# ##### #...# #####
输出#2
2
说明/提示
In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.
The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The deleted squares are marked with crosses.

在第一个样例中,你可以删除任意两个不共边的方格。删除后,被涂色的方格集合将不再连通。
第二个样例的说明如下图所示:左侧为初始方格集合的示意图;右侧为已删除若干方格后的集合,被删除的方格用“×”标记。

输入解题思路,AI测评打分。不知道怎么写?