From c432014637ccf9aa8a4ae33ed9bce84085ca5a35 Mon Sep 17 00:00:00 2001 From: ZeVicTech Date: Sat, 11 Feb 2023 23:12:03 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=B0=EA=B2=B0=20=EC=9A=94=EC=86=8C?= =?UTF-8?q?=EC=9D=98=20=EA=B0=9C=EC=88=98=20=EB=AC=B8=EC=A0=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230_\352\260\234\354\210\230.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "\352\271\212\354\235\264or\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211/\354\227\260\352\262\260_\354\232\224\354\206\214\354\235\230_\352\260\234\354\210\230.py" diff --git "a/\352\271\212\354\235\264or\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211/\354\227\260\352\262\260_\354\232\224\354\206\214\354\235\230_\352\260\234\354\210\230.py" "b/\352\271\212\354\235\264or\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211/\354\227\260\352\262\260_\354\232\224\354\206\214\354\235\230_\352\260\234\354\210\230.py" new file mode 100644 index 0000000..4b6f1f1 --- /dev/null +++ "b/\352\271\212\354\235\264or\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211/\354\227\260\352\262\260_\354\232\224\354\206\214\354\235\230_\352\260\234\354\210\230.py" @@ -0,0 +1,40 @@ +# https://www.acmicpc.net/problem/11724 + +from collections import deque + +n,m = map(int,input().split()) + +graph = [[] for _ in range(n+1)] + +for _ in range(m): + a,b = map(int,input().split()) + graph[a].append(b) + graph[b].append(a) + +visited = [0] * (n+1) + +def bfs(start): + queue = deque() + queue.append(start) + visited[start] == 1 + + while queue: + value = queue.popleft() + for item in graph[value]: + if visited[item] == 0: + queue.append(item) + visited[item] = 1 +cnt = 0 + +for i in range(1,n+1): + if visited[i] == 0: + bfs(i) + cnt += 1 + +print(cnt) + + + + + +