Problems
1. Babbity
Babbity the RabbityBabbity the Rabbity is visiting Carrotsmeade for a feast. Carrotsmeade is a well-planned village, and the is divided into N*M cells. Each cell contains either a carrot patch or a boulder. Each patch contains a given number of carrots. Babbity is allowed to land herself in any patch and explore around. While exploring Babbity can go to any of the four adjacent patches. Unfortunately, Babbity is a squib and hence cannot go through boulders. The entire village of Carrotsmeade is surrounded by boulders, and hence Babbity can never get out of it. A set of patches such that Babbity can reach any patch in the set from any other patch in the set is called a field. Your task is to find the number of fields in Carrotsmeade and the maximum number of carrots in any field.
Input Format:
- Line 1 : A single integer T, the number of testcases.
- This is followed by T test cases.
- First line of each test case consists of two integers N and M.
- This is followed by N lines of input with M integers each.
- The jth integer on the i+1th line of a particular testcase is 0 if a boulder is present at the cell (i,j), or a non-zero number giving the number of carrots in cell (i,j).
Output Format:
Output consists of T lines.
The ith line of the output contains the answer to the ith test case.
The output for each case consists of a single line with two space-separated integers, the number of fields in Carrotsmeade and the maximum number of carrots in any field, in that order.
Points:
300
Scoring:
Absolute Score = 1000000 / ( 5*S + 2*C + 10*K + 3*O )
where,
S = Number of semicolons ;
C = Number of non-whitespace characters
K = Number of keywords
O = Number of commas ,
Constraints:
1 <= T <= 10
3 <= N,M <= 1000
Allowed Header Files:
stdio.h
Sample Input:
2
3 3
0 0 0
0 4 0
0 0 0
6 5
0 0 0 0 0
0 4 0 1 0
0 2 3 0 0
0 1 0 0 0
0 0 2 9 0
0 0 0 0 0
Sample Output:
1 4
3 11