-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.py
49 lines (42 loc) · 1.06 KB
/
2.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
48
49
f=open('check.in', 'r')
t=open('check.out','w')
n=int(f.readline())
if n:
d=[0]*n
mas=[[0,0,0] for i in range(n)]
for i in range(n):
d=f.readline().split()
a,le,ri=int(d[0]),int(d[1]),int(d[2])
le-=1
ri-=1
mas[i][0]=a
mas[i][1]=le
mas[i][2]=ri
flag = 1
dl=[[0,10000000000,-10000000000]]
while dl and flag:
pars=dl.pop()
num=pars[0]
ap=pars[1]
al=pars[2]
a,le,ri = mas[num][0],mas[num][1],mas[num][2]
if a>=ap or a<=al:
flag=0
break
if le!=-1:
if mas[le][0] >= mas[num][0]:
flag=0
break
dl.append([le,a,al])
if ri!=-1:
if mas[ri][0] <= mas[num][0]:
flag=0
break
dl.append([ri,ap,a])
if flag:
print('YES',file = t)
else:
print('NO',file = t)
else:
print('YES',file = t)
t.close()