-
[백준 문제풀이] 얼렁뚱땅 11724번 연결 요소의 개수얼렁뚱땅 백준 문제풀이 2022. 4. 7. 21:28
import sys sys.setrecursionlimit(10**9) n, m = map(int,sys.stdin.readline().split()) connect = [[] for i in range(n+1)] visited = [False] * (n+1) for i in range(m) : temp = list(map(int,sys.stdin.readline().split())) temp.sort() connect[temp[0]].append(temp[1]) connect[temp[1]].append(temp[0]) def dfs(num) : if (visited[num] == False) : visited[num] = True for k in connect[num]: dfs(k) return True else : return False count = 0 for i in range(1,n+1) : if dfs(i) : count += 1 print(count)
흠
연결 요소의 개수를 구하는건데 왜 아무것도 연결 안되어 있는 것도 세야하는지 잘 모르겠다.
'얼렁뚱땅 백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이] 얼렁뚱땅 14248번 점프 점프 풀이 (0) 2022.04.08 [백준 문제풀이] 얼렁뚱땅 16173번 점프왕 쩰리(Small) 풀이 (0) 2022.04.08 [백준 문제풀이] 얼렁뚱땅 11265번 끝나지 않는 파티 풀이 (0) 2022.04.05 [백준 문제풀이] 얼렁뚱땅 11403번 경로찾기 풀이 (0) 2022.04.05 [백준 문제풀이] 얼렁뚱땅 18352번 특정 거리 도시 찾기 풀이 (0) 2022.04.05