Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.01 s | 3 KBi |
#2 |
Correcto
|
0.008 s | 4 KBi |
#3 |
Correcto
|
0.011 s | 3 KBi |
#4 |
Correcto
|
0.008 s | 3 KBi |
#5 |
Correcto
|
0.008 s | 4 KBi |
#6 |
Correcto
|
0.008 s | 3 KBi |
#7 |
Correcto
|
0.009 s | 4 KBi |
#8 |
Correcto
|
0.009 s | 3 KBi |
#9 |
Correcto
|
0.008 s | 3 KBi |
#10 |
Correcto
|
0.009 s | 3 KBi |
#11 |
Correcto
|
0.01 s | 3 KBi |
#12 |
Correcto
|
0.062 s | 6 KBi |
#13 |
Correcto
|
0.099 s | 7 KBi |
#14 |
Correcto
|
0.06 s | 6 KBi |
#15 |
Correcto
|
0.108 s | 7 KBi |
#16 |
Tiempo límite excedido
|
1.085 s | 14 KBi |
#17 |
Tiempo límite excedido
|
1.069 s | 10 KBi |
#18 |
Tiempo límite excedido
|
1.079 s | 10 KBi |
#19 |
Tiempo límite excedido
|
1.077 s | 9 KBi |
#20 |
Tiempo límite excedido
|
1.085 s | 9 KBi |
// 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); } } return false; } int32_t main() { fastInp; #if LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif 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; } return 0; }