π¦ μμ
1. λ¬Έμ λ§ν¬
2. μ½λ
Pypy3
136904KB
632ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
N = int(input())
workflow = [] # λ€μλ
Έλ
pre_workflow = [] # μ νλ
Έλ
in_degree = [0] * N # μ§μ
μ°¨μ
visit = [0] * N # λ°©λ¬Έ
time = []
for i in range(N):
workflow.append([])
pre_workflow.append([])
for i in range(N):
work = list(map(int, input().split()))
# 걸리λ μκ°
time.append(work[0])
# μ ν μμ
μ°κ²°
for j in range(work[1]):
pre_work = work[2 + j]
# λ€μμ μ§νν΄μΌνλ κ°μ μ°κ²°
workflow[pre_work - 1].append(i)
in_degree[i] += 1
# μ ν μμ
μΌλ‘λΆν° λ€μ΄μ€λ κ°μ μ°κ²°
pre_workflow[i].append(pre_work - 1)
# νμ¬ μμ
κΉμ§ μμλ μ΄ μκ°
dp = [0] * 10001
# μμμ λ ¬ ν
q = [0]
visit[0] = 1
total_time = 0
while q:
cur = q.pop(0)
# μ§μ
λ
Έλλ€μ μκ°μ κΈ°λ°μΌλ‘ νμ¬ μκ°μ μ§μ
pre_time = 0
for i in range(len(pre_workflow[cur])):
pre_time = max(pre_time, dp[pre_workflow[cur][i]])
dp[cur] = pre_time + time[cur]
total_time = max(total_time, dp[cur])
# λ€μ λ
Έλμ μ§μ
μ°¨μλ₯Ό μ κ±°
for i in range(len(workflow[cur])):
node = workflow[cur][i]
in_degree[node] -= 1
# μ§μ
μ°¨μκ° 0μΈ λ
Έλ νμ μ½μ
for i in range(N):
if not visit[i] and in_degree[i] == 0:
q.append(i)
visit[i] = 1
print(total_time)
3. ν΄μ€
λͺ¨λ λ Έλμ μ§μ λ Έλ, μ§μΆλ Έλλ₯Ό κΈ°λ‘νμ¬ μμμ λ ¬ μν μμ μ λ ¬ κ³Όμ μμ μ§μ λ Έλλ€μ μ΅λκ°μ κ°μ Έμ μ ν μμ μ΄ λͺ¨λ λλλ μκ° κ°μ Έμ΄ κ·Έ μκ° + νμ¬ μμ μ μκ°μΌλ‘ 걸리λ μκ°μ ν©μ ꡬν¨
This post is licensed under CC BY 4.0 by the author.