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

12-H0ngJu #180

merged 2 commits into from
May 6, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented Apr 9, 2024

πŸ”— 문제 링크

ABCDE

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

거의 2μ‹œκ°„

✨ μˆ˜λ„ μ½”λ“œ

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

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

이 문제 문제 μ„€λͺ…이 λ„ˆλ¬΄ λΆˆμΉœμ ˆν•΄μš”,,

문제 μ΄ν•΄ν•˜λŠ”λ° λ„ˆλ¬΄ μ˜€λž˜κ±Έλ Έμ–΄μš”. (심지어 그것도 κ²Œμ‹œνŒ 보고 이해함..)




첨에... κ·Έλƒ₯ λͺ¨λ“  μΉœκ΅¬λ“€μ΄ μ΄μ–΄μ ΈμžˆμœΌλ©΄ λ˜λ‚˜ ? ν•΄μ„œ μœ λ‹ˆμ˜¨ νŒŒμΈλ“œλ‘œ μ ‘κ·Όν–ˆλŠ”λ°,

문제 핡심이 κ·Έλƒ₯ 5λͺ…μ˜ 친ꡬ 이상이 일렬둜 λ‚˜μ—΄λ  수 있으면 λ˜λŠ” κ±°λ”λΌκ³ μš”....

κ·Έλž˜μ„œ λ°”λ‘œ λ°±νŠΈλž˜ν‚ΉμœΌλ‘œ 순회..

휴...

image




import sys
from collections import defaultdict

def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
graph = defaultdict(list)

def dfs(graph, now, depth, visited):
    if depth >= 5: return True

    for child in graph[now]:
        if child in visited: continue
        visited.add(child)
        result = dfs(graph, child, depth+1, visited)
        visited.discard(child)

        if result: return True

    return False

for _ in range(M):
    first, second = map(int, input().split())
    
    graph[first].append(second)
    graph[second].append(first)

for idx in range(N):
    result = dfs(graph, idx, 1, {idx,})

    if result: 
        print(1)
        break

else: print(0)

λ¬Έμ œκ°€.... κΉ”λ”ν•˜μ§€ λͺ»ν•˜λ‹€.... μ„€λͺ…이 더 ν•„μš”ν•˜λ‹€...

근데 μ „λ°˜μ μœΌλ‘œ ν™μ£Όλ‹˜ μ½”λ“œλ‚˜ 제 μ½”λ“œλ‚˜ λ‘œμ§μ€ κ°™λ„€μš”....!

μ•„μ£Ό λ„€μ΄μŠ€~~~~~~~~~


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만 μ‹œκ°„λ³΅μž‘λ„λ‹ˆκΉŒμš”...! )

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




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

Copy link

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

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

μ œκ°€ ν‘Ό μ½”λ“œλ„ 슬쩍... (λ‚˜λ¦„ κΉ”λ”ν•˜κ²Œ 잘 μ§  것 κ°™λ„€μš” :))
νƒœκ·œλ‹˜μ΄ 적어주신 λŒ€λ‘œ, stack λ‚΄ μ›μ†Œλ₯Ό copyν•˜λŠ” 건 μ‹œκ°„λ³΅μž‘λ„ μƒμœΌλ‘œ 쒋지 μ•ŠμŠ΅λ‹ˆλ‹€. λ°±νŠΈλž˜ν‚Ήμ΄λž€ κ°œλ…μ„ μ μš©ν•˜λ©΄ μ½”λ“œλ„ 간결해지고 μ²˜λ¦¬λ„ μ‰½κ²Œ ν•  수 있으며, κ°œλ… μžμ²΄κ°€ μ€‘μš”ν•˜κΈ°λ„ ν•©λ‹ˆλ‹€. κΌ­ ν•œ 번 ν™•μΈν•΄λ³΄μ„Έμš”!

input = open(0).readline

N, M = map(int, input().split())
graph = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    
visited = [False] * N


def dfs(src: int, depth: int = 0) -> bool:
    if depth == 4:
        return True
        
    visited[src] = True
    for dst in graph[src]:
        if visited[dst]:
            continue
        
        if dfs(dst, depth + 1):
            return True
            
    visited[src] = False
    return False
    

def solution() -> bool:
    for node in range(N):
        if visited[node]:
            continue
        
        if dfs(node):
            return True
            
    return False


print('1' if solution() else '0')

@H0ngJu H0ngJu merged commit c50ebb1 into main May 6, 2024
@H0ngJu H0ngJu deleted the 12-H0ngJu branch May 6, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants