#include #include #include #include #include using namespace std; int N,Q; vectorG[2<<17]; int L[2<<17]; bool vis[2<<17]; int main() { cin>>N; for(int i=1;i>L[i]>>A; G[A-1].push_back(i); } priority_queue >pq; pq.push(make_pair(0,0)); while(!pq.empty()) { int u=pq.top().second; int c=-pq.top().first; pq.pop(); if(vis[u])continue; vis[u]=true; L[u]=max(L[u],c); for(int v:G[u]) { assert(!vis[v]); pq.push(make_pair(-L[u],v)); } } vectorLv(N); for(int i=0;i>Q; for(;Q--;) { int op;cin>>op; if(op==1) { int x;cin>>x; cout<>y; y--; cout<<(vis[y]?L[y]:-1)<<"\n"; } } }