[XSY2525] Maze 2017 Multi - schools

Description

Consider a network of N × M grid, each grid is either empty, or an obstacle. The entire grid surrounded by walls (i.e., the first row and the n-th row, first column and the m-th column is the wall), and only two wall openings, representing the start and end. The starting point is always to the left of the grid, the end is always in the right grid. You can only move in four directions: up and down. Data to ensure there is at least one path from start to finish.

From the beginning to the end there may be many paths, find out how many must pass through the mesh grid all paths.

Input

The first line contains two integers N, M, N represents the mesh rows and M columns.

Next N lines of M symbols, represents the grid. '#' Represents a wall or obstacle, '' represents the open space.

Output

Output file contains an integer, by the number of necessary points.

Sample Input

7 7
#######
....#.#
#.#.###
#.....#
###.#.#
#.#....
#######

Sample Output

5

HINT

Sample interpretation

(2, 1) (2, 2) (4, 4) (6, 6) (6, 7)

Data range and Conventions

For 10% of the data, 3≤N, M≤50

For 50% of the data, 3≤N, M≤500

For all the data, 3≤N, M≤1000

Pre-knowledge --tarjan algorithm

Look at the problem.

The title said, requires that all paths must pass through a grid, like this description of an algorithm with the results of certain requirements are the same, what is it?

- percentage point.

We think about it, if a point is to go through all the paths of the grid, so if we get rid of this point what will happen?

- the starting and ending Unicom.

This is much like our point cut and the cutting edge.

In a connected graph, if we remove a point or an edge so that the remaining portion of FIG becomes not communicate, so that the point or the cutting edges is called the point (edge).

It is not like this question.

Then we say about solving the problem solution.

We enumerate each is not '#' points, with each point he was not around for the '#' side even side, then cut the number of points obtained this figure (not the start and end points), the answer plus 2 ( start and end points) and output.

Is not that a little truth?

However, this is very wrong.

Look at this picture

Guess you like

Origin www.cnblogs.com/2017gdgzoi44/p/11360542.html