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
44
45
|
from collections import deque
n = int(input())
graph = []
count = []
dx = [-1,1,0,0]
dy = [0,0,-1,1]
for _ in range(n):
graph.append(list(map(int,input())))
def apt(x,y):
que = deque()
que.append((x,y))
j = 0
count = [0]
while que:
x,y = que.popleft()
if graph[x][y] == 1 or graph[x][y]==2:
if graph[x][y]==1:
count[0] += 1
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx<0 or ny<0 or nx>=n or ny>=len(graph[0]):
continue
if graph[nx][ny]==0:
continue
if graph[nx][ny]==1:
que.append((nx,ny))
graph[x][y]=2
graph[nx][ny]=2
count[0]+=1
return count
result = 0
for k in range(n):
for l in range(len(graph[0])):
count.append(apt(k,l))
for a in range(len(count)):
count = [i for i in count if not 0 in i]
count.sort()
print(len(count))
for a in range(len(count)):
print(count[a][0])
|
cs |
'백준' 카테고리의 다른 글
백준 10773번: 제로 (0) | 2021.05.18 |
---|---|
백준 2108번: 통계학 (0) | 2021.05.18 |
백준 9012번: 괄호 (0) | 2021.05.07 |
백준 1978번: 소수 찾기 (0) | 2021.05.07 |
백준 1929번: 소수 구하기 (0) | 2021.05.07 |