Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.008 s | 4 KBi |
#2 |
Incorrecto
|
0.008 s | 3 KBi |
#3 |
Incorrecto
|
0.009 s | 4 KBi |
#4 |
Correcto
|
0.01 s | 3 KBi |
#5 |
Incorrecto
|
0.005 s | 3 KBi |
#6 |
Incorrecto
|
0.008 s | 3 KBi |
#7 |
Incorrecto
|
0.008 s | 4 KBi |
#8 |
Incorrecto
|
0.011 s | 3 KBi |
#9 |
Incorrecto
|
0.008 s | 3 KBi |
#10 |
Incorrecto
|
0.004 s | 3 KBi |
#11 |
Incorrecto
|
0.011 s | 4 KBi |
#12 |
Incorrecto
|
0.252 s | 12 KBi |
#13 |
Incorrecto
|
0.41 s | 13 KBi |
#14 |
Correcto
|
0.217 s | 12 KBi |
#15 |
Incorrecto
|
0.343 s | 13 KBi |
#16 |
Tiempo límite excedido
|
1.061 s | 29 KBi |
#17 |
Tiempo límite excedido
|
1.063 s | 24 KBi |
#18 |
Tiempo límite excedido
|
1.084 s | 25 KBi |
#19 |
Tiempo límite excedido
|
1.089 s | 23 KBi |
#20 |
Tiempo límite excedido
|
1.102 s | 23 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]; unordered_map<int, set<int>> mp; bool dfs(int u, int search){ for (auto x: g[u]){ mp[x].insert(u); if (x == search){ mp[x].insert(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; } if (mp.find(b) != mp.end()){ if (mp[b].find(a) != mp[b].end()){ cout << "Yes" << endl; continue; } } cout << (dfs(b, a) ? "Yes" : "No") << endl; } return 0; }