From b7e69ed153acba29bc97e41110850caaabdd1562 Mon Sep 17 00:00:00 2001 From: YeIn kim <2076070@ewhain.net> Date: Tue, 6 May 2025 23:44:56 +0900 Subject: [PATCH] =?UTF-8?q?[Baekjoon-2606]=20=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 --- ...24\354\235\264\353\237\254\354\212\244.py" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "BOJ/yein/13_week/\353\260\224\354\235\264\353\237\254\354\212\244.py" diff --git "a/BOJ/yein/13_week/\353\260\224\354\235\264\353\237\254\354\212\244.py" "b/BOJ/yein/13_week/\353\260\224\354\235\264\353\237\254\354\212\244.py" new file mode 100644 index 0000000..dc984ac --- /dev/null +++ "b/BOJ/yein/13_week/\353\260\224\354\235\264\353\237\254\354\212\244.py" @@ -0,0 +1,80 @@ +# DFS로 풀기 +# N = 컴퓨터의 수 +N=int(input()) + +# M = 컴퓨터 쌍의 수 +M = int(input()) +# 컴퓨터 쌍 +dict = {} +for _ in range(M): + a, b = map(int, input().split()) + if(a not in dict): + dict[a] = [b] + else: + dict[a].append(b) + if(b not in dict): + dict[b] = [a] + else: + dict[b].append(a) + +# print(dict) + +# 탐색 시작~ +curr = 1 +global ans +ans = 0 +visited = [] + +def dfs(curr): + global ans + if(curr in dict): + for c in dict[curr]: + if (c not in visited): + visited.append(c) + if (not c==1): ans += 1 + dfs(c) + +dfs(curr) +print(ans) + +# # BFS로 구현 +# # N = 컴퓨터의 수 +# N=int(input()) + +# # M = 컴퓨터 쌍의 수 +# M = int(input()) +# # 컴퓨터 쌍 +# dict = {} +# for _ in range(M): +# a, b = map(int, input().split()) +# if(a not in dict): +# dict[a] = [b] +# else: +# dict[a].append(b) +# if(b not in dict): +# dict[b] = [a] +# else: +# dict[b].append(a) + +# from collections import deque +# q = deque() +# curr = 1 +# # global ans +# ans = 0 +# visited = [] + +# def bfs(curr): +# global ans +# q.append(curr) +# visited.append(curr) +# while(q): +# curr= q.popleft() +# if(curr in dict): +# for c in dict[curr]: +# if(c not in visited): +# visited.append(c) +# if (not c==1): ans += 1 +# q.append(c) + +# bfs(curr) +# print(ans) \ No newline at end of file