Submission #207403

#TimeUsernameProblemLanguageResultExecution timeMemory
207403mohamedsobhi777Birthday gift (IZhO18_treearray)C++17
0 / 100
8 ms2680 KiB
#include<bits/stdc++.h> using namespace std ; const int N = 1e5 + 7 ; int n , t , m, q; vector<int> adj[N] ; vector<int> path; int st[N] , en[N] ; int a[N]; void dfs(int x , int p) { st[x] = t++ ; path.push_back(x); for(auto u : adj[x]) { if(u==p) continue; dfs(u , x) ; } en[x] = t++; path.push_back(x) ; } bool inside(int L, int R , int l , int r) { return (l>=L && l<=R && r>=L && r<=R); } int main() { cin>>n>>m>>q; for(int i = 0 ; i < n-1 ; i++) { int a, b ; cin>>a>>b ; adj[a].push_back(b) ; adj[b].push_back(a) ; } dfs(1 , 1) ; for(int i = 0 ; i<m ; i++) { cin>>a[i] ; } while(q--) { int idx , A , B; cin>>idx>>A>>B ; if(idx==1) { a[A-1] = B; } else { int C; cin>>C ; int l = st[C] , r = en[C] ; int nodeA = -2 , nodeB = -2; for(int i = A-1 ; i<=B-1 ;i++) { if(nodeA!=-2) break; int mL = 1e8 , mR = -1e8 ; for(int j = i ; j<=B-1 ; j++) { mL = min(mL , st[a[j]] ) ; mR = max(mR , en[a[j]] ) ; if(mL==l+1 || mR==r-1 || (mL==l&& mR==r) ) { nodeA = i ; nodeB = j ; break; } } } cout<<nodeA+1<<" " <<nodeB+1<<"\n" ; } } return 0 ; } /* 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...