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

Envío 6109

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

  • Autor: Jorgito
  • Fecha: 2022-05-23 18:57:42 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
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
#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.014 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.01 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.011 s 3 KBi
#5
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
#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.017 s 3 KBi
#8
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
#9
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.021 s 3 KBi
#10
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.017 s 3 KBi
#11
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.011 s 3 KBi
#12
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.143 s 21 KBi
#13
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.178 s 21 KBi
#14
Incorrecto
0.261 s 21 KBi
#15
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.164 s 21 KBi
#16
Incorrecto
0.242 s 21 KBi
#17
Incorrecto
0.705 s 22 KBi
#18
Incorrecto
0.224 s 21 KBi
#19
Incorrecto
0.235 s 22 KBi
#20
Incorrecto
0.256 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')