File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 9.31 MB, 시간: 0.49 ms
7+ 메모리: 9.25 MB, 시간: 0.52 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 11월 09일 22:50:30
19+ 2025년 12월 31일 13:23:52
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11from collections import deque
22
33def solution (n , computers ):
4+ visited = [False ] * n
5+ cnt = 0
46
5- def bfs (start ):
6- q = deque ([start ])
7- visited [start ] = True
7+ def bfs (i ):
8+ q = deque ([i ])
9+ visited [i ] = True
810
911 while q :
10- A = q .popleft ()
11- for neighbor in range (n ):
12- if computers [A ][neighbor ] == 1 and not visited [neighbor ]:
13- visited [neighbor ] = True
14- q .append (neighbor )
15-
12+ now = q .popleft ()
13+ for j in range (n ):
14+ if computers [now ][j ] == 1 and not visited [j ]:
15+ q .append (j )
16+ visited [j ] = True
1617
17- visited = [False ] * n
18- ans = 0
1918 for i in range (n ):
2019 if not visited [i ]:
2120 bfs (i )
22- ans += 1
23-
24- return ans
21+ cnt += 1
22+ return cnt
You can’t perform that action at this time.
0 commit comments