-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyuzin02.py
34 lines (29 loc) · 811 Bytes
/
yuzin02.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
import sys
sys.setrecursionlimit(10000)
def dfs(x, y):
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if (0 <= nx < N) and (0 <= ny < M):
if graph[nx][ny] == 1:
graph[nx][ny] = -1
dfs(nx, ny)
T = int(input())
for _ in range(T):
M, N, K = map(int, input().split())
graph = [[0]*M for _ in range(N)]
cnt = 0
for _ in range(K):
m, n = map(int, input().split())
graph[n][m] = 1 # IndexError: list index out of range 실수 조심
print(graph)
for i in range(N):
for j in range(M):
print('hey')
if graph[i][j] > 0:
print('why')
dfs(i, j)
cnt += 1
print(cnt)