From 4c54f35b4d9092a8c56e60aea6ea1ca29cc8f836 Mon Sep 17 00:00:00 2001 From: Jiyun Kim Date: Wed, 17 May 2023 20:10:55 +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=A4BFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\235\264\353\237\254\354\212\244BFS.py" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244BFS.py" diff --git "a/\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244BFS.py" "b/\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244BFS.py" new file mode 100644 index 0000000..8a7e510 --- /dev/null +++ "b/\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244BFS.py" @@ -0,0 +1,27 @@ +import sys +from collections import deque + +N = int(sys.stdin.readline()) +C = int(sys.stdin.readline()) + +graph = [[] for i in range(N+1)] + +for i in range(C): + a, b = map(int,sys.stdin.readline().split()) + graph[a].append(b) + graph[b].append(a) + +visited = [] +def bfs(x): + q = deque([x]) + visited.append(x) + + while q: + v = q.popleft() + for i in graph[v]: + if i not in visited: + q.append(i) + visited.append(i) + +bfs(1) +print(len(visited) -1) # 1번 컴퓨터는 제외 From efb8cb1a28da844799aef52ffc7e735c562e1bb9 Mon Sep 17 00:00:00 2001 From: Jiyun Kim Date: Wed, 17 May 2023 20:13:01 +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=A4DFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\235\264\353\237\254\354\212\244DFS.py" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244DFS.py" diff --git "a/\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244DFS.py" "b/\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244DFS.py" new file mode 100644 index 0000000..0702772 --- /dev/null +++ "b/\354\235\264\355\213\260\354\247\200\354\234\244/2606_\353\260\224\354\235\264\353\237\254\354\212\244DFS.py" @@ -0,0 +1,27 @@ +import sys + +n = int(sys.stdin.readline()) # 컴퓨터의 개수 +m = int(sys.stdin.readline()) # 쌍의 개수 + +graph = [[] for _ in range(n + 1)] + +for i in range(m): + a, b = map(int, input().split()) + graph[a].append(b) + graph[b].append(a) + +result = 0 +visited = [0] * (n + 1) + + +def dfs(start): + global result + visited[start] = 1 + for j in graph[start]: + if visited[j] == 0: + result += 1 + dfs(j) + + +dfs(1) +print(result) \ No newline at end of file