From 4f2026e4a8c235fb1aa7a93e0562548221b529d5 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 9 Apr 2024 12:08:09 +0900 Subject: [PATCH] 2024-04-09 --- H0ngJu/DFS/ABCDE.py | 43 +++++++++++++++++++++++++++++++++++++++++++ H0ngJu/README.md | 19 ++++++++++--------- 2 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 H0ngJu/DFS/ABCDE.py 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 eea8f055..1da5a7b5 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,13 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | -| 2차시 | 2024.03.07 | 큐 | [다리를 지나는 트럭](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 | -| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | -| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | -| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | -| 6차시 | 2024.03.19 | 스택 | [오큰수](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | -| 7차시 | 2024.03.22 | DP | [1,2,3 더하기](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | +| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 2차시 | 2024.03.07 | 큐 | [다리를 지나는 트럭](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 | +| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | +| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | +| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | +| 6차시 | 2024.03.19 | 스택 | [오큰수](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | +| 7차시 | 2024.03.22 | DP | [1,2,3 더하기](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | +| 12차시 | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 | ---