From dbfc98d59f8438d902f8b697d5f70ee9ec867b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=98=88=EC=9B=90?= <78153914+yewonahn@users.noreply.github.com> Date: Wed, 17 May 2023 19:59:08 +0900 Subject: [PATCH] =?UTF-8?q?#21=20:=202606=5F=EB=B0=94=EC=9D=B4=EB=9F=AC?= =?UTF-8?q?=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #21 : Week5_예원이티 --- ...24\354\235\264\353\237\254\354\212\244.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\230\210\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" diff --git "a/\354\235\264\355\213\260\354\230\210\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" "b/\354\235\264\355\213\260\354\230\210\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" new file mode 100644 index 0000000..7c0c54a --- /dev/null +++ "b/\354\235\264\355\213\260\354\230\210\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" @@ -0,0 +1,24 @@ +from collections import deque + +computer = int(input()) +v = int(input()) +graph = [[] for i in range(computer+1)] +visited = [0]*(computer+1) + +for i in range(v): + a, b = map(int, input().split()) + graph[a] += [b] + graph[b] += [a] + + +visited[1] = 1 +Q = deque([1]) + +while Q: + c = Q.popleft() + for nx in graph[c]: + if visited[nx]==0: + Q.append(nx) + visited[nx]=1 + +print(sum(visited)-1)