baekjoon 20251226
This commit is contained in:
parent
6c5c41c27e
commit
8e78f3629e
@ -1,29 +1,30 @@
|
|||||||
import heapq
|
from collections import deque
|
||||||
import sys
|
import sys
|
||||||
input = sys.stdin.readline
|
input = sys.stdin.readline
|
||||||
|
|
||||||
N, M = map(int, input().split())
|
N, M = map(int, input().split())
|
||||||
|
|
||||||
graph = [[] for _ in range(N+1)]
|
graph = [[] for _ in range(N+1)]
|
||||||
inDegree = [0]*(N+1)
|
indegree = [0]*(N+1)
|
||||||
|
|
||||||
for _ in range(M) :
|
for _ in range(M) :
|
||||||
u, v = map(int, input().split())
|
a, b = map(int, input().split())
|
||||||
graph[u].append(v)
|
graph[a].append(b)
|
||||||
inDegree[v] += 1
|
indegree[b] += 1
|
||||||
|
|
||||||
|
qu = deque()
|
||||||
|
|
||||||
pq = []
|
|
||||||
for i in range(1,N+1) :
|
for i in range(1,N+1) :
|
||||||
if inDegree[i] == 0 :
|
if indegree[i] == 0 :
|
||||||
heapq.heappush(pq, i)
|
qu.append(i)
|
||||||
|
|
||||||
result = []
|
ans = []
|
||||||
while len(pq) :
|
while qu :
|
||||||
current = heapq.heappop(pq)
|
now = qu.popleft()
|
||||||
result.append(str(current))
|
ans.append(str(now))
|
||||||
|
|
||||||
for next in graph[current] :
|
for next in graph[now] :
|
||||||
inDegree[next] -= 1
|
indegree[next] -= 1
|
||||||
if inDegree[next] == 0 :
|
if indegree[next] == 0 :
|
||||||
heapq.heappush(pq, next)
|
qu.append(next)
|
||||||
|
|
||||||
print(" ".join(result))
|
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