https://programmers.co.kr/learn/courses/30/lessons/43162
코딩테스트 연습 - 네트워크
네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있
programmers.co.kr
위문제는 컴퓨터들의 상호된 네트워크의 갯수를 구하는 문제이다.
나의 경우 DFS를 이용하여 전체 컴퓨터를 돌며 컴퓨터마다 연결된 네트워크를 체크하며 갯수를 늘려주게 하였다.
def solution(n,computers):
answer = 0
visit = [0] * n
def dfs(now):
visit[now] = 1
for i in range(n):
if computers[now][i]==1 and visit[i]!=1:
dfs(i)
for i in range(n):
if visit[i] !=1:
dfs(i)
answer+=1
return answer
'Algorithm > programmers' 카테고리의 다른 글
programmers 신고 결과 받기 (0) | 2022.07.26 |
---|---|
프로그래머스: 굿스타터 스킬레벨체크1(python) (0) | 2022.07.26 |
programmers 카펫(완전탐색) (0) | 2022.06.14 |
programmers 단어 변환(DFS/BFS) (0) | 2022.06.08 |
programmers 타겟넘버(DFS/BFS) (0) | 2022.06.08 |
댓글