-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaek_1012.py
38 lines (31 loc) · 975 Bytes
/
Baek_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
import sys
t = int(sys.stdin.readline())
for i in range(t):
m, n, k = map(int, sys.stdin.readline().split())
a = []
for j in range(k):
b, c = map(int,sys.stdin.readline().split())
a.append((b,c))
u = []
while a:
b = []
c = []
c.append(a[0])
del a[0]
while c:
d = c.pop()
b.append(d)
if (d[0]+1,d[1]) in a:
c.append((d[0]+1,d[1]))
a.remove((d[0]+1,d[1]))
if (d[0]-1,d[1]) in a:
c.append((d[0]-1,d[1]))
a.remove((d[0]-1,d[1]))
if (d[0],d[1]+1) in a:
c.append((d[0],d[1]+1))
a.remove((d[0],d[1]+1))
if (d[0],d[1]-1) in a:
c.append((d[0],d[1]-1))
a.remove((d[0],d[1]-1))
u.append(len(c))
print(len(u))