게시글
고민있어요
2024.01.14 02:22
고민있어요 ㅠㅠ
- 0
- 1
- 242
질문&답변
2023.11.21
11724 문제 질문
import sys import collections sys.setrecursionlimit(10**6) input = sys.stdin.readline N, M = map(int, input().split()) dic = collections.defaultdict(list) visited = [] result = 0 for _ in range(M): x, y = map(int, input().split()) dic[x].append(y) dic[y].append(x) def dfs(node): global visited, dic visited.append(node) for n in dic[node]: if n not in visited: dfs(n) for node in list(dic.keys()): if node not in visited: dfs(node) result += 1 print(result)
- 1
- 2
- 220
고민있어요
2023.11.21 17:08
graph를 만들 때
- 1
- 1
- 142