From e542060c6c70e1c062ae2b2a29664e36db0d0083 Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Wed, 17 May 2023 21:23:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#21=20:=202606=5F=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EB=9F=AC=EC=8A=A4=5FDFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\235\264\353\237\254\354\212\244_DFS.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.py" diff --git "a/\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.py" "b/\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.py" new file mode 100644 index 0000000..106e2c1 --- /dev/null +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.py" @@ -0,0 +1,19 @@ +import sys + +n=int(sys.stdin.readline()) +m=int(sys.stdin.readline()) +graph = [[] for i in range(n+1)] +visited=[0]*(n+1) + +for i in range(m): + a,b=map(int,input().split()) + graph[a]+=[b] + graph[b]+=[a] + +def dfs(m): + visited[m]=1 + for i in graph[m]: + if visited[i]==0: + dfs(i) +dfs(1) +print(sum(visited)-1) From 3a551e56a5f406f0fe254950f4bf3586c6dca521 Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Wed, 17 May 2023 21:24:48 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#21=20:=202606=5F=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EB=9F=AC=EC=8A=A4=5FBFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\235\264\353\237\254\354\212\244_BFS.py" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.py" diff --git "a/\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.py" "b/\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.py" new file mode 100644 index 0000000..758d0f2 --- /dev/null +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.py" @@ -0,0 +1,31 @@ +import sys +from collections import deque + +n = int(sys.stdin.readline()) +m = int(sys.stdin.readline()) +graph = [[] for i in range(n+1)] +visited = [False]*(n+1) + + +for i in range(m): + a, b = map(int, input().split()) + + graph[a].append(b) + graph[b].append(a) + +def bfs(graph, v): + cnt = 0 + queue = deque([v]) + + while queue: + pop = queue.popleft() + visited[pop] = True + + for i in graph[pop]: + if visited[i]==False: + visited[i] = True + queue.append(i) + cnt += 1 + print(cnt) + +bfs(graph, 1) \ No newline at end of file