class Solution:

    def makeConnected(self, n: int, connections: List[List[int]]) -> int:

        if len(connections) + 1 < n:

            return -1

        graph = [[] for _ in range(n)]

        visit = [0 for _ in range(n)]

        for start, end in connections:

            graph[start].append(end)

            graph+.append(start)

        queue = deque()

        cnt = 0

        for i in range(n):

            if visit[i] == 0:

                queue.append(i)

                visit[i] == 1

                cnt += 1

                while queue:

                    cur = queue.popleft()

                    for nxt in graph[cur]:

                        if visit[nxt] == 0:

                            visit[nxt] = 1

                            queue.append(nxt)

        return cnt-1


도대체 connected component 갯수(+ 엣지 갯수 체크) 구하는게 왜 medium..

문제만 올리니까 공허하네....

최근에 공부한, 혹은 뉴비용 알고리즘 설명이라도 올려봐야겠다.