Skip to content

Commit

Permalink
Merge pull request #180 from AlgoLeadMe/12-H0ngJu
Browse files Browse the repository at this point in the history
12-H0ngJu
  • Loading branch information
H0ngJu authored May 6, 2024
2 parents 3fe0703 + 5a653be commit c50ebb1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions H0ngJu/DFS/ABCDE.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

---

0 comments on commit c50ebb1

Please sign in to comment.