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

52-tgyuuAn #182

Merged
merged 1 commit into from
May 10, 2024
Merged

52-tgyuuAn #182

merged 1 commit into from
May 10, 2024

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented May 6, 2024

πŸ”— 문제 링크

κ²Œμž„ 개발

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

20λΆ„

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

이 문제, 문제λ₯Ό 읽어보면 μ•Œκ² μ§€λ§Œ ACM Craft와 맀우 λΉ„μŠ·ν•˜λ‹€. μ•„λ‹ˆ κ°™λ‹€.

#61 (comment)

5/8일 μžˆμ„ ν”„λ‘œκ·Έλž˜λ° κ²½μ§„λŒ€νšŒλ₯Ό μœ„ν•΄μ„œ μœ„μƒμ •λ ¬μ„ λ³΅κΈ°ν•˜λŠ” 마음으둜 λ‹€μ‹œ ν’€μ–΄λ³΄μ•˜λ”°.

image

μ§„μ§œ 근데 풀이가 μœ„λž‘ λ„ˆλ¬΄ λ˜‘κ°™μ•„μ„œ... μΆ”κ°€μ μœΌλ‘œ μ“Έ λ‚΄μš©μ΄ ν•˜ν•˜.

ν™μ£Όλ‹˜ν•œν…ŒλŠ” μ£„μ†‘ν•˜μ§€λ§Œ μœ„μ— μœ„μƒμ •λ ¬ κ΄€λ ¨ν•΄μ„œ λ‚΄μš© λ‹€λ‹€λ‹€λ‹€ μ¨λ†¨μœΌλ‹ˆ 읽어보길 μΆ”μ²œν•œλ‹€!

ν‚€ν‚€ 이번 PR은 날먹해야지

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

@tgyuuAn tgyuuAn added tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. μž‘μ„± 쀑 ⏱️ labels May 6, 2024
@tgyuuAn tgyuuAn requested review from Munbin-Lee and H0ngJu May 6, 2024 17:47
@tgyuuAn tgyuuAn self-assigned this May 6, 2024
@tgyuuAn tgyuuAn marked this pull request as ready for review May 7, 2024 08:12
Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

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

전에 λ¬Έμ œμ§‘ ν’€λ©΄μ„œ 봀던 μœ„μƒμ •λ ¬ λ‹€μ‹œ λ³΅μŠ΅ν•˜κ³  κ°‘λ‹ˆλ‹€!!

μ²˜μŒμ—” λ™μ‹œμ— 건물 μ—¬λŸ¬κ°œλ₯Ό 지을 수 μžˆλ‹€λŠ”κ±Έ λͺ¨λ₯΄κ³  ν•œλ²ˆμ— ν•˜λ‚˜μ”© μ§“λŠ” 쀄 μ•Œκ³  ν’€μ—ˆμŠ΅λ‹ˆλ‹€ γ…‹.γ…‹
문제 해석을 잘λͺ»ν•΄λ†“κ³€ μ™œ 틀렸지?? ν•˜κ³  ν•œμ°Έ λ΄€λ„€μš”;; γ…‹γ…‹γ…‹γ…‹

λ¬Έμ œν‘ΈλŠλΌ κ³ μƒν•˜μ…¨μŠ΄λ‹€ ~!!

N = int(input())
#κ±Έλ¦¬λŠ” μ‹œκ°„ / λ¨Όμ € μ§€μ–΄μ Έμ•Όν•˜λŠ” 건물의 번호
building = [list(map(int, input().split())) for _ in range(N)]

time = 0
result = [0 for _ in range(N+1)]
inDegree = [0 for _ in range(N+1)]
next_building = [[] for _ in range(N+1)]
q = []

for i in range(N):
    time = building[i][0]
    result[i+1] = time
    for x in building[i][1:]:
        if x != -1:
            next_building[x].append(i+1)
            inDegree[i+1] += 1

# μ§„μž…μ°¨μˆ˜κ°€ 0이면 큐에 λ„£κΈ°
for i in range(1, N+1):
    if inDegree[i] == 0:
        heapq.heappush(q, i)

while q:
    cur = heapq.heappop(q)

    for i in next_building[cur]:
        result[i] = max(result[i], result[cur]+building[i-1][0])
        inDegree[i] -= 1
        if inDegree[i] == 0:
            heapq.heappush(q, i)

now = can_build.pop()

for next_building in outdegree[now]:
indegree[next_building][1].discard(now)
Copy link
Collaborator

Choose a reason for hiding this comment

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

μ €λŠ” 이전에 지어져야 ν•  건물을 κ·Έλƒ₯ list둜 μ €μž₯ν•΄μ„œ μΌλŠ”λ°,, set으둜 μ €μž₯해두면 discardλ₯Ό μ‚¬μš©ν•˜λ©΄ λ˜λŠ”κ΅°μš© ..
discard 처음 λ³΄λ„€μš” κ°’μ˜ μ‘΄μž¬ν•¨μ΄ 보μž₯되면 remove(), 보μž₯λ˜μ§€ μ•ŠμœΌλ©΄ discard() 쀍쀍 ν•΄κ°‘λ‹ˆλ‹€!!

Copy link
Member Author

Choose a reason for hiding this comment

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

@H0ngJu

근데 μƒκ°ν•΄λ³΄λ‹ˆ μ•žμ— 지어져야 ν•  건물 번호λ₯Ό ꡳ이 μ €μž₯ν•˜μ§€ μ•Šκ³  홍μ₯¬λ₯΄κ°€ ν‘Ό λ°©μ‹λŒ€λ‘œ indegree둜만 κ΄€λ¦¬ν•˜λŠ” 것이 훨씬 μ’‹μ•„λ³΄μ΄λŠ”λ°μš”?

μ–΄μ°¨ν”Ό μœ„μƒμ •λ ¬μ΄λ‹ˆκΉŒ ν•œ λ²ˆμ”©λ§Œ κ±΄μ„€λ ν…Œλ‹ˆκΉŒ................................ ꡉμž₯ν•΄ μ—„μ²­λ‚˜...............

0μΌλ•Œλ§Œ heap에 λ„£κ²Œ ν•΄μ„œ 이미 지어진 건물듀은 음수둜 κ°€λ²„λ¦¬λ‹ˆκΉŒ... μ™€μš°

@tgyuuAn
Copy link
Member Author

tgyuuAn commented May 10, 2024

전에 λ¬Έμ œμ§‘ ν’€λ©΄μ„œ 봀던 μœ„μƒμ •λ ¬ λ‹€μ‹œ λ³΅μŠ΅ν•˜κ³  κ°‘λ‹ˆλ‹€!!

μ²˜μŒμ—” λ™μ‹œμ— 건물 μ—¬λŸ¬κ°œλ₯Ό 지을 수 μžˆλ‹€λŠ”κ±Έ λͺ¨λ₯΄κ³  ν•œλ²ˆμ— ν•˜λ‚˜μ”© μ§“λŠ” 쀄 μ•Œκ³  ν’€μ—ˆμŠ΅λ‹ˆλ‹€ γ…‹.γ…‹ 문제 해석을 잘λͺ»ν•΄λ†“κ³€ μ™œ 틀렸지?? ν•˜κ³  ν•œμ°Έ λ΄€λ„€μš”;; γ…‹γ…‹γ…‹γ…‹

λ¬Έμ œν‘ΈλŠλΌ κ³ μƒν•˜μ…¨μŠ΄λ‹€ ~!!

N = int(input())
#κ±Έλ¦¬λŠ” μ‹œκ°„ / λ¨Όμ € μ§€μ–΄μ Έμ•Όν•˜λŠ” 건물의 번호
building = [list(map(int, input().split())) for _ in range(N)]

time = 0
result = [0 for _ in range(N+1)]
inDegree = [0 for _ in range(N+1)]
next_building = [[] for _ in range(N+1)]
q = []

for i in range(N):
    time = building[i][0]
    result[i+1] = time
    for x in building[i][1:]:
        if x != -1:
            next_building[x].append(i+1)
            inDegree[i+1] += 1

# μ§„μž…μ°¨μˆ˜κ°€ 0이면 큐에 λ„£κΈ°
for i in range(1, N+1):
    if inDegree[i] == 0:
        heapq.heappush(q, i)

while q:
    cur = heapq.heappop(q)

    for i in next_building[cur]:
        result[i] = max(result[i], result[cur]+building[i-1][0])
        inDegree[i] -= 1
        if inDegree[i] == 0:
            heapq.heappush(q, i)

μ•„λ‹ˆ μœ„μƒ 정렬도 ν’€ 쀄 μ•„λŠ” μ‹ΈλžŒμ΄μ—ˆλ„€....!!

@tgyuuAn tgyuuAn merged commit ed97c91 into main May 10, 2024
1 check passed
@tgyuuAn tgyuuAn deleted the 52-tgyuuAn branch May 10, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
H0ngJu tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. 리뷰 μ™„λ£Œ βœ”οΈ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants