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

Envío 7012

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

  • Autor: danidiaztech
  • Fecha: 2023-06-07 16:36:25 UTC (Hace más de 1 año)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.007 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.007 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.009 s 4 KBi
#4
Correcto
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
0.012 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.007 s 3 KBi
#6
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.007 s 4 KBi
#7
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.008 s 3 KBi
#8
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.007 s 3 KBi
#9
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.008 s 4 KBi
#10
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.009 s 3 KBi
#11
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.006 s 4 KBi
#12
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.062 s 7 KBi
#13
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.037 s 6 KBi
#14
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.058 s 6 KBi
#15
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.04 s 6 KBi
#16
Tiempo límite excedido
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
1.073 s 14 KBi
#17
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.059 s 10 KBi
#18
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.048 s 10 KBi
#19
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.046 s 9 KBi
#20
Error en tiempo de ejecución (NZEC)
                      main.cpp:38:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

                    
Exited with error status 132
run.sh: line 1:     3 Illegal instruction     (core dumped) ./a.out
0.055 s 9 KBi
Puntos totales: 5 / 100

Código

// Made by Daniel Diaz (@Danidiaztech)
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define forn(i, n) for (int i = 0; i < n; i++) // for in range in python
#define fore(i, a, b) for (int i = a; i < b; i++) // for in range in python
#define int long long int
#define double long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size() 

typedef pair<int, int> pii;
typedef vector<int> vii;

const int MAX = 1e5 + 10;
const int MIN = -MAX;
const int oo = LLONG_MAX / 2;
const int ooo = LLONG_MIN / 2;
const int mod = 1e9 + 7;

vii g[MAX];

bool dfs(int u, int search){
  for (auto x: g[u]){
    if (x == search){
      return true;
    }
    else{
      return dfs(x, search);
    }
  }
}

void solve(){
  int n;
  cin >> n;
  forn(i,n - 1){
    int a, b; cin >> a >> b;
    g[b].pb(a);
  }
  int q; cin >> q;
  forn(i,q){
    int a, b; cin >> a >> b;
    if (a == b){
      cout << "Yes" << endl; continue;
    }
    cout << (dfs(b, a) ? "Yes" : "No") << endl;
  }
}

int32_t main() {
  fastInp;
  #if LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int tc = 1;
  // cin >> tc;

  for (int t = 1; t <= tc; t++){
    // cout << "Case #" << t << ": ";
    solve();
  }
  return 0;
}