Depth-first search on a matrix · Compiler
Depth-first search on a matrix
Use depth-first search to measure the patch of 1s containing the specified cell. A patch joins only cells that share a side. Count each reachable 1 once. A starting cell containing 0 has patch size 0.
- Input
- The first line contains r c sr sc (1 <= r,c <= 30). The starting row sr and column sc are 0-based from the top left, with 0 <= sr < r and 0 <= sc < c. The next r lines each contain c binary digits with no spaces.
- Output
- Print the patch size as one integer.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…