Skip to content

Commit b7d9831

Browse files
committed
[level 3] Title: 네트워크, Time: 0.52 ms, Memory: 9.25 MB -BaekjoonHub
1 parent 8e85807 commit b7d9831

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

프로그래머스/3/43162. 네트워크/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 9.31 MB, 시간: 0.49 ms
7+
메모리: 9.25 MB, 시간: 0.52 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 11월 09일 22:50:30
19+
2025년 12월 31일 13:23:52
2020

2121
### 문제 설명
2222

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
from collections import deque
22

33
def 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

0 commit comments

Comments
 (0)