ALLIZWEL - ALL IZZ WELL


Mr.ESP used to tell “ALL IZZ WELL” whenever he gets into any trouble. So his friends and the people around him used to laugh at him. But Mr.ESP is very strong in his belief. He believes that the term “ALL IZZ WELL” will make everything fine. Now your task is to ignore the story above and find whether there is a path in the given matrix which makes the sentence “ALL IZZ WELL”

There is a path from any cell to all its neighbouring cells. A neighbour may share an edge or a corner.

Input Specification:

The first line consists of an integer t representing the number of test cases.

The first line of each test case consists of two integers R and C representing the number of rows and number of columns in the matrix. The description of the matrix follows.

Output Specification:

For each test case print “YES” if there is a path which makes the sentence “ALLIZZWELL”. Else print “NO”.

Note: Take care of 4th test case

There is a new line after every test case in the input.

Input constraints:

t <= 1000
R <= 100
C <= 100

Sample Input:

5
3 6
AWE.QX
LLL.EO
IZZWLL

1 10
ALLIZZWELL

2 9
A.L.Z.E..
.L.I.W.L.

3 3
AEL
LWZ
LIZ

1 10
LLEWZZILLA
Sample Output:
YES
YES
NO
NO
YES

hide comments
KD : 2016-02-25 10:25:50

AC in one go :)

spoj1984: 2016-02-09 18:52:28

Is there a tricky test case or something else?
I tried it several times but I got WA !

Last edit: 2016-02-11 00:17:10
darkhire21: 2015-12-26 17:13:49

for ans of Karan2K testcase is ans of yvn ....!!
nice question .

Riddhi: 2015-10-23 09:06:35

Thanks @Karan2k for ur test case

Saurabh Sameer: 2015-09-25 09:55:14

Hahaha!!!Problem description is just too good :)

Harsh Vardhan Ladha: 2015-09-08 16:44:50

got 3WAs just because wrong markdown of output overhere -_-
Matrix + DFS

dev: 2015-08-27 18:03:43

first ever dfs prob ! Ac ;)

rushikesh: 2015-07-11 22:16:18

whats wrong with my code please help beginner here code id 14649989

janina: 2015-06-26 18:50:29

@Rohit Gupta ....i think u are missing the conditions when i and/or j in the bfs function goes out of bound and while backtracking unvisiting the checker array .....by the way.....good one :)

Last edit: 2015-06-26 18:53:07
yvn: 2015-06-22 09:19:25

@Rohit Gupta when you are backtracking do make the cell unvisited


Added by:cegprakash
Date:2011-12-25
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64