-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1012.py
More file actions
39 lines (28 loc) · 703 Bytes
/
1012.py
File metadata and controls
39 lines (28 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 유기농 배추
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
t = int(input())
mx = [1, -1, 0, 0]
my = [0, 0, 1, -1]
def dfs(x, y):
if x < 0 or x >= n or y < 0 or y >= m:
return False
if farm[x][y] == 1:
farm[x][y] = 0
for i in range(4):
dfs(x + mx[i], y + my[i])
return True
return False
for _ in range(t):
n, m, k = map(int, input().split())
farm = [[0] * m for _ in range(n)]
count = 0
for _ in range(k):
x, y = map(int, input().split())
farm[x][y] = 1
for i in range(n):
for j in range(m):
if dfs(i, j):
count += 1
print(count)