All Tracks Basic Programming Recursion Recursion and Backtracking Problem

biggest forest
/
No tags
Problem
Editorial
Analytics

Imagine the field is a 2D plane. Each cell is either water 'W' or a tree 'T'. 
A forest is a collection of connected trees. Two trees are 
connected if they share a side i.e. if they are adjacent to each other.

Your task is, given the information about the field, print the size of the largest forest.

Size of a forest is the number of trees in it. See the sample case for clarity

INPUT:

First line contains the size of the matrix N. 
The next N lines contain N characters each, either 'W' or 'T'.

OUTPUT:

Print the size of the biggest forest.

CONSTRAINTS:

1<=N<=1000

SAMPLE INPUT
5
TTTWW
TWWTT
TWWTT
TWTTT
WWTTT
SAMPLE OUTPUT
10
Explanation

The forest on the top left has 6 trees but the forest on the
bottom right is bigger with 10 trees

Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

Initializing Code Editor...
Notifications
View All Notifications

?