All Submissions


You are given the map of Byteland.You have to count the number of different land masses(islands).The map will be in rectangular form.
Two cells are connected if they share a common edge.

INPUT
The first line of input will contain the number of test cases,T.Each test case will begin with two integers,N and M,indicating the dimensions of the map.
Next N lines will contain M integers(either 0 or 1),representing a cell of the map.
0 represents water and 1 represents land.

OUTPUT
For each test case print the number of islands in separate line.

CONSTRAINT
Number of test case T will be more than 0 and less than 25.
N will be more than 0 and less than 25.
M will be more than 0 and less than 25.

Sample Input

2
4 5
1 1 0 0 0
1 1 1 1 0
0 0 0 1 0
1 1 0 0 0
3 3
0 0 1
0 1 0
1 0 0

Sample Output

2
3


Problem Setter : Akshay Kumar

Languages: Brain,C,C++,Java,Pascal,Perl,PHP,Python,Ruby,Text

Time Limit: 1 Second(s)
Score: 0 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

No Clarifications.

Contest

Mode Judge

Passive

Online

Overall Rankings

RankNameScore
1xyz0
2Ams0
3TIP0
4team420
5xyzz0
6asdasdasd0
7abcd0
8khankhan0
9Gabriel0
10gigel0