Search

์กฐ์˜ˆ์ง€

2.๋ฌธ์ œ์ด๋ฆ„
3. ์ˆ˜ํ–‰์‹œ๊ฐ„[์ดˆ(s)]
1800
4. git ์ฃผ์†Œ URL
์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ
์ข‹์•„์š” ์ˆ˜
: 0
5 more properties
| ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
from collections import deque def bfs(n, computers, par): queue = deque() queue.append(n) while queue: now = queue.popleft() for i in range(len(computers[now])): if computers[now][i] == 1 and i != now and par[i] == i: queue.append(i) par[i] = now def solution(n, computers): par = [i for i in range(len(computers))] cnt = 0 for i in par: if par[i] == i: bfs(i, computers, par) cnt += 1 return cnt
Python
๋ณต์‚ฌ
| ์ฝ”๋“œ ์„ค๋ช…ํ•˜๊ธฐ
์ฒ˜์Œ์—๋Š” ์„œ๋กœ์†Œ ์ง‘ํ•ฉ์„ ์ƒ๊ฐํ–ˆ๋‹ค๊ฐ€ BFS์™€ ์งฌ๋ฝ•์ด ๋˜์—ˆ๋‹ค.