Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m, n = map(int, input().split())
- g = []
- for i in range(m):
- g.append(list(input()))
- def dfs(x, y):
- g[x][y] = '.'
- for xp, yp in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
- if 0 <= xp < m and 0 <= yp < n:
- if g[xp][yp] == '#':
- dfs(xp, yp)
- count = 0
- for x in range(m):
- for y in range(n):
- if g[x][y] == '#':
- count += 1
- dfs(x, y)
- print(count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement