From 8e78f3629edfa3ecfe45ab18e7221dff48c43ead Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Fri, 26 Dec 2025 23:41:24 +0900 Subject: [PATCH] baekjoon 20251226 --- code_study/Baekjoon/python/2252.py | 41 ++++++++++++++-------------- code_study/Baekjoon/swift/5543.swift | 6 ++++ 2 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 code_study/Baekjoon/swift/5543.swift diff --git a/code_study/Baekjoon/python/2252.py b/code_study/Baekjoon/python/2252.py index fbf72f2..c008a8d 100644 --- a/code_study/Baekjoon/python/2252.py +++ b/code_study/Baekjoon/python/2252.py @@ -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)) \ No newline at end of file +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)) \ No newline at end of file diff --git a/code_study/Baekjoon/swift/5543.swift b/code_study/Baekjoon/swift/5543.swift new file mode 100644 index 0000000..c14cdb3 --- /dev/null +++ b/code_study/Baekjoon/swift/5543.swift @@ -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) +}