█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6110

Problema 0x1c - Decir si un nodo es ancestro de otro en un árbol

  • Autor: Jorgito
  • Fecha: 2022-05-23 19:00:22 UTC (Hace casi 2 años)
Caso # Resultado Tiempo Memoria
#1
Tiempo límite excedido
1.599 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 19, in <module>
    parent = arbol[child]
KeyError: '0'
0.02 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 19, in <module>
    parent = arbol[child]
KeyError: '0'
0.014 s 3 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 19, in <module>
    parent = arbol[child]
KeyError: '0'
0.03 s 4 KBi
#5
Tiempo límite excedido
1.584 s 5 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 19, in <module>
    parent = arbol[child]
KeyError: '0'
0.019 s 3 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 19, in <module>
    parent = arbol[child]
KeyError: '0'
0.01 s 3 KBi
#8
Tiempo límite excedido
1.514 s 5 KBi
#9
Tiempo límite excedido
1.578 s 3 KBi
#10
Tiempo límite excedido
1.599 s 3 KBi
#11
Tiempo límite excedido
1.599 s 3 KBi
#12
Tiempo límite excedido
1.566 s 22 KBi
#13
Tiempo límite excedido
1.6 s 21 KBi
#14
Tiempo límite excedido
1.59 s 21 KBi
#15
Tiempo límite excedido
1.56 s 21 KBi
#16
Tiempo límite excedido
1.601 s 21 KBi
#17
Tiempo límite excedido
1.546 s 21 KBi
#18
Tiempo límite excedido
1.599 s 21 KBi
#19
Tiempo límite excedido
1.535 s 21 KBi
#20
Tiempo límite excedido
1.521 s 21 KBi
Puntos totales: 0 / 100

Código

N = int(input())

arbol = {}
for i in range(N-1):
    arbolData = input().split() #[0, 1] 0 is ancestor and 1 is child
    # key=child and value=parent  {'1':'0'}
    arbol[arbolData[1]] = arbolData[0]


c = int(input())
for i in range(c):
    query = input().split(' ')
    ancestor = query[0]
    child   = query[1]

    if ancestor == child:
        print('Yes')

    parent = arbol[child]
    while parent is not None:
        if parent == ancestor:
            print('Yes')
            break
    
    print('No')