Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 1 KBi |
#2 |
Correcto
|
0.003 s | 12 KBi |
#3 |
Correcto
|
0.004 s | 0 KBi |
#4 |
Correcto
|
0.005 s | 8 KBi |
#5 |
Correcto
|
0.004 s | 7 KBi |
#6 |
Correcto
|
0.004 s | 14 KBi |
#7 |
Correcto
|
0.003 s | 2 KBi |
#8 |
Correcto
|
0.004 s | 1 KBi |
#9 |
Correcto
|
0.004 s | 14 KBi |
#10 |
Correcto
|
0.004 s | 12 KBi |
#11 |
Correcto
|
0.004 s | 4 KBi |
#12 |
Correcto
|
0.166 s | 8 KBi |
#13 |
Correcto
|
0.123 s | 7 KBi |
#14 |
Correcto
|
0.178 s | 7 KBi |
#15 |
Correcto
|
0.126 s | 7 KBi |
#16 |
Correcto
|
0.133 s | 53 KBi |
#17 |
Correcto
|
0.127 s | 17 KBi |
#18 |
Correcto
|
0.113 s | 20 KBi |
#19 |
Correcto
|
0.128 s | 14 KBi |
#20 |
Correcto
|
0.119 s | 14 KBi |
/// Write by Daniel Perez .PERAPRO #include<bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define ff first #define ss second #define all(s) s.begin(), s.end() typedef long long ll; typedef unsigned long long ull; typedef long double ld; using vi=vector<int>; using vl=vector<ll>; using pii=pair<int,int>; char el = '\n'; char esp = ' '; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ostream& operator<<(ostream& os, const vector<int> &v){ for(auto const &i: v){ os<<i<<" "; } os<<'\n'; return os; } string yes="YES"; string no="NO"; int main(){ fast_io; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ int n,a,b; cin>>n; vector<vi> g(n); for(int i=1;i<n;i++){ cin>>a>>b; g[a].pb(b), g[b].pb(a); } int timer = 0; vi in(n), out(n); function<void(int, int)> dfs = [&] (int u, int p){ in[u] = timer++; for(int v:g[u]){ if(v == p) continue; dfs(v, u); } out[u] = timer; }; dfs(0, -1); int q; cin>>q; //cout<<in<<out; while(q--){ cin>>a>>b; //a es ancestro de b, b hace parte del subarbol de a? cout<<(in[b] >= in[a] && out[b] <= out[a] ? "Yes" : "No")<<el; } } /* */