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

Envío 6108

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

  • Autor: Jorgito
  • Fecha: 2022-05-23 18:54:04 UTC (Hace casi 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.015 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.021 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.013 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.018 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.015 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.017 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.009 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 20, 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.009 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.009 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.01 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.137 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.181 s 21 KBi
#14
Incorrecto
0.254 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 20, in <module>
    parent = arbol[child]
KeyError: '0'
0.164 s 21 KBi
#16
Incorrecto
0.235 s 21 KBi
#17
Incorrecto
0.204 s 21 KBi
#18
Incorrecto
0.208 s 21 KBi
#19
Incorrecto
0.246 s 21 KBi
#20
Incorrecto
0.24 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('Noe')