baekjoon 20251226

This commit is contained in:
songyc macbook 2025-12-26 23:41:24 +09:00
parent 6c5c41c27e
commit 8e78f3629e
2 changed files with 27 additions and 20 deletions

View File

@ -1,29 +1,30 @@
import heapq
from collections import deque
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
graph = [[] for _ in range(N+1)]
inDegree = [0]*(N+1)
indegree = [0]*(N+1)
for _ in range(M) :
u, v = map(int, input().split())
graph[u].append(v)
inDegree[v] += 1
a, b = map(int, input().split())
graph[a].append(b)
indegree[b] += 1
qu = deque()
pq = []
for i in range(1,N+1) :
if inDegree[i] == 0 :
heapq.heappush(pq, i)
result = []
while len(pq) :
current = heapq.heappop(pq)
result.append(str(current))
for next in graph[current] :
inDegree[next] -= 1
if inDegree[next] == 0 :
heapq.heappush(pq, next)
if indegree[i] == 0 :
qu.append(i)
print(" ".join(result))
ans = []
while qu :
now = qu.popleft()
ans.append(str(now))
for next in graph[now] :
indegree[next] -= 1
if indegree[next] == 0 :
qu.append(next)
print(" ".join(ans))

View File

@ -0,0 +1,6 @@
if let prices = (1...5).compactMap({_ in Int(readLine() ?? "")}) as? [Int],
let burger = prices.prefix(3).min(),
let drink = prices.suffix(2).min()
{
print(burger + drink - 50)
}