-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
106 lines (78 loc) · 3.07 KB
/
Copy pathmain.py
File metadata and controls
106 lines (78 loc) · 3.07 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from make_it import make_it
dict_of_roads = make_it()
print(dict_of_roads)
def check_if_visited(array, visited):
"""
Tato funkce ověří, jestli nejde už o navštívenou node
:param array: ten array co je v dictu
:param visited: průběžný visited,co jsou
:return: True/ False array, kde True znamená, že to nejde použít
"""
b = []
for i in array:
if i[0] in visited:
b.append(True)
else:
b.append(False)
return b
def check_length_from_node(array, dict_of_roads, visited):
"""
Tato funkce ověří, že příští bod, splňuje podmínku 2 km
:param array: ten array co je v dictu
:param dict_of_roads: to původní co je udělaný díky funkci make_it
:param visited: průběžný visited
:return: vratí to list True/False, Kde True zanemná, že to nejde použít
"""
b = []
for i in array:
c = dict_of_roads[i[0]]
r = []
for j in c:
if j[1] <= 2:
if j[0] in visited:
r.append(True)
else:
r.append(False)
else:
r.append(False)
b.append(any(r))
return b
def main(dict_of_roads, where_wanna_start, visited):
visited = []
sum = 0
current_adding = 0
value_where_are_we_now = where_wanna_start
been_check_the_length_and_visited = check_length_from_node(dict_of_roads[value_where_are_we_now], dict_of_roads,
visited)
while not all(been_check_the_length_and_visited):
visited.append(value_where_are_we_now)
for i in range(len(been_check_the_length_and_visited)):
if been_check_the_length_and_visited[i] is False:
if dict_of_roads[value_where_are_we_now][i][0] in visited:
if len(been_check_the_length_and_visited) == 1:
b = visited.pop()
dict_of_roads[visited[-1]] = dict_of_roads[visited[-1]][1:]
t = main(dict_of_roads, visited[-1], visited)
if (t + sum) - current_adding > sum:
sum -= current_adding
sum += t
return t
been_check_the_length_and_visited[i] = True
continue
else:
current_adding = dict_of_roads[value_where_are_we_now][i][1]
sum += dict_of_roads[value_where_are_we_now][i][1]
value_where_are_we_now = dict_of_roads[value_where_are_we_now][i][0]
been_check_the_length_and_visited = check_length_from_node(dict_of_roads[value_where_are_we_now],
dict_of_roads, visited)
break
return sum
a = main(dict_of_roads, 2, [])
where_we_are = 0
sum = 0
for i in range(74418):
b = main(dict_of_roads, i, [])
if b > sum:
sum = b
where_we_are = i
print(sum)