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

4-H0ngJu #158

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: |
| 1μ°¨μ‹œ | 2024.03.05 | 큐 | [ν”„λ‘œμ„ΈμŠ€](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
| 4μ°¨μ‹œ | 2024.03.13 | νž™ | [λ¬Έμ œμ§‘](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 |

---
32 changes: 32 additions & 0 deletions H0ngJu/νž™/λ¬Έμ œμ§‘.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
import heapq
Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

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

from heapq import *

λͺ¨λ“ˆ μž„ν¬νŠΈ ν•  λ•Œ μœ„μ²˜λŸΌ ν•˜λ©΄ μ’€ 더 νŽΈν•˜κ²Œ μ½”λ”©ν•  수 μžˆλ‹΅λ‹ˆλ‹€
λ”°λ‘œ heapqλ₯Ό μ•ˆ μ¨μ€˜λ„ λΌμš”

heappush(heap, value)


n, m = map(int, sys.stdin.readline().rstrip().split())

graph = [[] for _ in range(n+1)]
inDegree = [0 for _ in range(n+1)]
Copy link
Member

Choose a reason for hiding this comment

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

μ‚¬μ†Œν•œ κ±°κΈ΄ ν•œλ°, νŒŒμ΄μ¬μ€ κ³΅μ‹μ μœΌλ‘œ snake 기법을 μ»¨λ²€μ…˜μœΌλ‘œ μ±„νƒν•˜κ³ μžˆμ–΄μš”!

Copy link
Member

Choose a reason for hiding this comment

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

μ™œμ£ ?

q = []
answer = []

# μž…λ ₯λ°›μ•„μ„œ λ„£κΈ°
for _ in range(m):
p1, p2 = map(int, sys.stdin.readline().rstrip().split())
Copy link
Member

@tgyuuAn tgyuuAn Mar 13, 2024

Choose a reason for hiding this comment

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

이 뢀뢄도 λ―Έμ„Έ νŒμ΄κΈ΄ν•œλ°

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

으둜 μ„ μ–Έν•΄λ†“μœΌλ©΄

p1, p2 = map(int, input().split())

으둜 μ‚¬μš©ν•  수 μžˆμ–΄μš”!

(dx, dy κΈ‰ λ―Έμ„Έ κΏ€νŒμž…λ‹ˆλ‹€.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

흐흐 λ°”μ•„λ‘œ 이번 λ¬Έμ œμ— μ μš©ν–ˆμŠ΅λ‹ˆλ‹€πŸ˜†πŸ˜Ž

graph[p1].append(p2) # p1은 p2와 μ—°κ²°λœ 문제
inDegree[p2] += 1 # κ°„μ„  μΆ”κ°€

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

# answer에 λ„£κ³ , κ°„μ„  제거
while q:
prob = heapq.heappop(q)
answer.append(prob)
for i in graph[prob]: # κ°„μ„  제거 & μ§„μž…μ°¨μˆ˜ 0인 것듀 처리
inDegree[i] -= 1
if inDegree[i] == 0:
heapq.heappush(q, i)

for result in answer:
print(result, end=" ")