Submit | All submissions | Best solutions | Back to list |
MAKEMAZE - VALIDATE THE MAZE |
There are many algorithms to generate maze. (http://en.wikipedia.org/wiki/Maze_generation_algorithm). After generating the maze we’ve to validate whether it’s a valid maze or not. A valid maze has exactly one entry point and exactly one exit point (exactly 2 openings in the edges) and there must be at least one path from the entry point to exit point.
Given a maze, just find whether the maze is "valid" or "invalid".
Input
The first line consists of an integer t, the number of test cases. Then for each test case, the first line consists of two integers m and n, the number of rows and columns in the maze. Then contains the description of the matrix M of order mxn. M[i][j]=# represents a wall and M[i][j]='.' represents a space.
Output
For each test case find whether the maze is "valid" or "invalid".
Constraints
1<=t<=10000
1<=m<=20
1<=n<=20
Example
Input: 6 4 4 #### #... #.## #.## 5 5 #.### #..## ##..# #.#.# ###.# 1 1 . 5 1 # # . . # 2 2 #. .# 3 4 #..# #.## #.## Output: valid valid invalid valid invalid invalid
Added by: | cegprakash |
Date: | 2012-05-11 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU |
hide comments
|
||||||||||||
2013-12-12 23:21:48 Simón Murillo Gómez
@himanshu jain is invalid "A valid maze has exactly one entry point and exactly one exit point (EXACTLY 2 OPENINGS IN THE EDGES)" |
||||||||||||
2013-12-12 23:21:48 himanshu jain
is this case a valid case? 4 5 5 ##.## ##.#. #..## #.### #.### i have 3 openings , but one cannot be used as entry/exit |
||||||||||||
2013-12-12 23:21:48 vishal chaudhary
i m getting SIGSEGV error , my code id is 7485646 ...plz help..:( |
||||||||||||
2013-12-12 23:21:48 Swapnil R.Mehta
Got AC! Last edit: 2012-08-16 10:19:45 |
||||||||||||
2013-12-12 23:21:48 cegprakash
@Prabhat: .## .## is a valid maze |
||||||||||||
2013-12-12 23:21:48 winner
Last edit: 2012-07-29 08:41:44 |
||||||||||||
2013-12-12 23:21:48 ♘Prabhat
what is answer of this .## .## and if these mazes are equivalent ________ .............# ________| Last edit: 2012-07-29 08:45:51 |
||||||||||||
2013-12-12 23:21:48 Aditya Pande
Last edit: 2012-12-18 15:53:47 |
||||||||||||
2013-12-12 23:21:48 Zhouxing Shi
I got WA all the time,could you @pandian @cegprakash tell me why ? THANKS. What does "in the corner" mean? REPLY: sorry, it's actually edges Last edit: 2012-07-26 10:47:20 |
||||||||||||
2013-12-12 23:21:48 Ehor Nechiporenko
Could you please answer 2 questions? 1) Is there whitespace between . and # characters in input? 2) Is corner point both entry and exit? |