Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.009 s | 4 KBi |
#2 |
Correcto
|
0.009 s | 3 KBi |
#3 |
Correcto
|
0.008 s | 3 KBi |
#4 |
Correcto
|
0.008 s | 4 KBi |
#5 |
Correcto
|
0.013 s | 3 KBi |
#6 |
Correcto
|
0.01 s | 4 KBi |
#7 |
Correcto
|
0.01 s | 3 KBi |
#8 |
Correcto
|
0.013 s | 3 KBi |
#9 |
Correcto
|
0.009 s | 3 KBi |
#10 |
Correcto
|
0.008 s | 4 KBi |
#11 |
Correcto
|
0.01 s | 3 KBi |
#12 |
Correcto
|
0.141 s | 7 KBi |
#13 |
Correcto
|
0.141 s | 7 KBi |
#14 |
Correcto
|
0.17 s | 7 KBi |
#15 |
Correcto
|
0.158 s | 7 KBi |
#16 |
Tiempo límite excedido
|
1.068 s | 6 KBi |
#17 |
Tiempo límite excedido
|
1.08 s | 7 KBi |
#18 |
Tiempo límite excedido
|
1.066 s | 6 KBi |
#19 |
Tiempo límite excedido
|
1.091 s | 7 KBi |
#20 |
Tiempo límite excedido
|
1.08 s | 6 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; } queue<int> q; q.push(b); bool f= 0; while (!q.empty() && !f){ int u = q.front(); q.pop(); for (auto x: g[u]){ if (x == a){ f = 1; break; } else{ q.push(x); } } } cout << (f?"Yes":"No") << endl; } return 0; }