Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12-H0ngJu #180

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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이 λ§Œλ“€μ–΄μ Έμ„œ 전달 κ°€λŠ₯
Copy link
Member

@tgyuuAn tgyuuAn Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μΉ΄ν”Όν•˜λŠ” 것도 λ‘œμ§μ€ κ°™κΈ΄ν•œλ°,

μ‹œκ°„ λ³΅μž‘λ„κ°€ 짱짱 많이 λ“€μž–μ•„μš”...!

(λ§Œμ•½ 데이터가 10만개면 10만 μ‹œκ°„λ³΅μž‘λ„λ‹ˆκΉŒμš”...! )

λ°±νŠΈλž˜ν‚Ή μ΄λΌλŠ” 것을 ν•œλ²ˆ μ°Ύμ•„λ³΄μ‹œκ² μ–΄μš” ?!




홍μ₯¬λ₯΄ ν•  수 μžˆλ‹€ ν•  수 μžˆλ”°~

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 |

---