Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.009 s | 3 KBi |
#2 |
Correcto
|
0.026 s | 6 KBi |
#3 |
Correcto
|
0.021 s | 3 KBi |
#4 |
Correcto
|
0.009 s | 3 KBi |
#5 |
Correcto
|
0.009 s | 3 KBi |
#6 |
Correcto
|
0.014 s | 3 KBi |
#7 |
Correcto
|
0.022 s | 3 KBi |
#8 |
Correcto
|
0.029 s | 3 KBi |
#9 |
Incorrecto
|
0.01 s | 3 KBi |
#10 |
Correcto
|
0.01 s | 3 KBi |
#11 |
Correcto
|
0.026 s | 7 KBi |
#12 |
Incorrecto
|
1.167 s | 21 KBi |
#13 |
Incorrecto
|
1.015 s | 21 KBi |
#14 |
Incorrecto
|
0.752 s | 23 KBi |
#15 |
Incorrecto
|
0.563 s | 21 KBi |
#16 |
Tiempo límite excedido
|
1.563 s | 21 KBi |
#17 |
Tiempo límite excedido
|
1.548 s | 21 KBi |
#18 |
Tiempo límite excedido
|
1.549 s | 21 KBi |
#19 |
Tiempo límite excedido
|
1.601 s | 21 KBi |
#20 |
Tiempo límite excedido
|
1.577 s | 21 KBi |
N = int(input()) tree = {} memo = {} for i in range(N - 1): treeData = input().split(' ') tree[treeData[1]] = treeData[0] C = int(input()) for i in range(C): wasYes = False query = input().split(' ') ancestor = query[0] child = query[1] if ancestor == '0' or ancestor == child: print('Yes') continue try: parent = tree[child] except: parent = None while parent is not None: if parent == ancestor: print('Yes') wasYes = True break if parent < ancestor: break try: parent = tree[parent] except: parent = None if not wasYes: print('No')