Skip to content

Commit

Permalink
Create 11724.py
Browse files Browse the repository at this point in the history
  • Loading branch information
park1997 committed Jul 18, 2022
1 parent e538d10 commit c3942c8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions BOJ_11xxx/11724.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 연결요소의 개수
from collections import deque
import sys
def bfs(start):
global visited
global graph
q = deque()
q.append(start)
visited[start] = True
while q:
s = q.popleft()
for k in graph[s]:
if not visited[k]:
q.append(k)
visited[k] = True


N,M = map(int,sys.stdin.readline().split())
graph = [[] for _ in range(N+1)]
visited = [False]*(N+1)
for i in range(M):
a,b = map(int,sys.stdin.readline().split())
graph[a].append(b)
graph[b].append(a)
cnt = 0
for i in range(1,N+1):
if not visited[i]:
bfs(i)
cnt +=1
print(cnt)

0 comments on commit c3942c8

Please sign in to comment.