diff --git a/H0ngJu/DFS/ABCDE.py b/H0ngJu/DFS/ABCDE.py new file mode 100644 index 00000000..913bdcd3 --- /dev/null +++ b/H0ngJu/DFS/ABCDE.py @@ -0,0 +1,43 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +# 재귀함수 fr_check +def fr_check(friend, stack): + stack.append(friend) # 현재 친구를 스택에 추가 + print(stack) + + if len(stack) == 5: # 친구 5명 되면 + return stack + + for x in friends[friend]: + if x not in stack: + result = fr_check(x, stack.copy()) # 복사해야 별도의 stack이 만들어져서 전달 가능 + if result is not None: + return result + + return None # stack이 5가 되지 않은 경우 + + +N, M = map(int, input().split()) +friends = [[] for _ in range(N)] #freind[i]에는 i의 친구 담기 +fcheck = 0 +stack = [] + + +for _ in range(M): + f0, f1 = map(int, input().split()) + friends[f0].append(f1) + friends[f1].append(f0) + + +for idx in range(N): + stack = [] + result = fr_check(idx, stack) #idx부터 체크 시작 + if result != None and len(result) == 5: + fcheck = 1 + print("1") + break + +if fcheck == 0: + print(0) \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index c14c8707..362c56db 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -13,5 +13,6 @@ | 9차시 | 2024.03.22 | DP | [RGB거리 2](https://www.acmicpc.net/problem/17404) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/172 | | 10차시 | 2024.04.03 | BFS | [숨바꼭질 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 | | 11차시 | 2024.04.07 | 구현 | [사탕 게임](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/178 | +| 12차시 | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 | ---