baekjoon 20251226
This commit is contained in:
parent
6c5c41c27e
commit
8e78f3629e
@ -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))
|
||||
6
code_study/Baekjoon/swift/5543.swift
Normal file
6
code_study/Baekjoon/swift/5543.swift
Normal 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)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user