-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1012-유기농 배추.py
43 lines (36 loc) · 969 Bytes
/
1012-유기농 배추.py
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
36
37
38
39
40
41
42
43
def Find_path(x,y):
if arr[x][y] == 1:
arr[x][y] = 0
if x == M-1 and y == N-1:
elif x == M-1 :
elif y == N-1:
if x == 0 and y == 0:
Find_path(x,y+1)
Find_path(x+1,y)
elif x == 0:
Find_path(x,y-1)
Find_path(x,y+1)
elif y == 0:
Find_path(x-1,y)
Find_path(x+1,y)
else:
Find_path(x-1,y)
Find_path(x+1,y)
Find_path(x,y-1)
Find_path(x,y+1)
T = int(input())
global M,N,K
for _ in range(T):
M,N,K = map(int,input().split())
arr = [[0 for __ in range(M)] for ___ in range(N)]
for i in range(K):
X,Y = map(int, input().split())
arr[Y][X] = 1
cnt = 0
for i in range(N):
for j in range(M):
if arr[i][j] == 1:
Find_path(j,i)
cnt += 1
print(arr)
print(cnt)