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

Envío 5607

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

  • Autor: bryancalisto
  • Fecha: 2022-01-23 01:49:05 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#2
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#3
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#4
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#5
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#6
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#7
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#8
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#9
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#10
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#11
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#12
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#13
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#14
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#15
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#16
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#17
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#18
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#19
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
#20
Error de compilación
                      main.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
N = int(input())
^
main.c:1:5: error: expected expression
N = int(input())
    ^
main.c:44:20: error: expected ';' after top level declarator
        print('No')
                   ^
                   ;
1 warning and 2 errors generated.

                    
Puntos totales: 0 / 100

Código

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]
    memo[child] = {}

    if ancestor == '0' or ancestor == child:
        print('Yes')
        continue

    try:
        parent = tree[child]
    except:
        parent = None

    print(memo)

    while parent is not None:
        if parent == ancestor or (parent in memo and ancestor in memo[parent]):
            print('Yes')
            wasYes = True
            break

        memo[child][parent] = True

        try:
            parent = tree[parent]
        except:
            parent = None

    if not wasYes:
        print('No')