-
Notifications
You must be signed in to change notification settings - Fork 2
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
4-H0ngJu #158
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
import heapq | ||
|
||
n, m = map(int, sys.stdin.readline().rstrip().split()) | ||
|
||
graph = [[] for _ in range(n+1)] | ||
inDegree = [0 for _ in range(n+1)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ¬μν κ±°κΈ΄ νλ°, νμ΄μ¬μ 곡μμ μΌλ‘ snake κΈ°λ²μ 컨벀μ μΌλ‘ μ±ννκ³ μμ΄μ! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 κΈ λ―ΈμΈ κΏνμ λλ€.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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=" ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λͺ¨λ μν¬νΈ ν λ μμ²λΌ νλ©΄ μ’ λ νΈνκ² μ½λ©ν μ μλ΅λλ€
λ°λ‘ heapqλ₯Ό μ μ¨μ€λ λΌμ