-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodil4.py
47 lines (36 loc) · 1.02 KB
/
codil4.py
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
# you can write to stdout for debugging purposes, e.g.
from extratypes import Tree # library with types used in the task
#scan tree fid longes path with no dups
def is_unique(path):
x={}
for p in path:
if p in x :
return False
else:
x[p]=1
return True
def solution(T):
stk=[]
stkpar=[]
stk.append(T)
pathr=[T.x]
stkpar.append(pathr)
mymax=1
while len(stk)>0:
n=stk.pop()
path1=stkpar.pop()
path2=path1.copy()
print(n.x)
if n.l != None :
stk.append(n.l)
path1.append(n.l.x)
stkpar.append(path1)
if is_unique(path1) and len(path1)>mymax:
mymax=len(path1)
if n.r != None :
stk.append(n.r)
path2.append(n.r.x)
stkpar.append(path2)
if is_unique(path2) and len(path2)>mymax:
mymax=len(path2)
return mymax