-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmin_compile_time.py
More file actions
56 lines (48 loc) · 1.52 KB
/
min_compile_time.py
File metadata and controls
56 lines (48 loc) · 1.52 KB
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
55
56
import sys
from typing import List
class Node:
def __init__(self, id, val):
self.id = id
self.val = val
self.children = []
class Solution:
def __init__(self, target):
self.target = target
def get_res(self, nodes: List[Node]):
return self.get_max_route(nodes, target)
def get_max_route(self, nodes: List[Node], cur):
# print(nodes[cur].id)
# print(nodes[cur].val)
# print(nodes[cur].children)
if nodes[cur].children == []:
return nodes[cur].val
else:
max_val = 0
for id in nodes[cur].children:
chi_val = self.get_max_route(nodes, id)
max_val = max_val if max_val > chi_val else chi_val
return max_val + nodes[cur].val
if __name__ == "__main__":
# 输入这么恶心,真有你的。
has_tar = False
target = 0
i = 1
nodes = [Node(-1, -1) for _ in range(50001)]
for line in sys.stdin:
if not has_tar:
target = int(line[6:])
has_tar = True
continue
values = list(map(str, line.split(",")))
if values == ['\n']:
break
id = int(values[0][6:])
val = int(values[1])
node = Node(id, val)
nodes[i] = node
i += 1
for i in range(2, len(values)):
cid = int(values[i][6:])
node.children.append(cid)
sol = Solution(target)
print(sol.get_res(nodes))