#include using namespace std; #define rep(i,n) for(int i=0; i; using TU = tuple; using vint = vector; using vvint = vector; using vvvint = vector; using vll = vector; using vvll = vector; using vvvll = vector; template istream &operator>>(istream &is,vector &v){for(T &in:v){is>>in;}return is;} template ostream &operator<<(ostream &os,vector &v){for(int i=0;i<(int)v.size();i++){os< istream &operator>>(istream &is,vector> &v){for(vector &in:v){is>>in;}return is;} template ostream &operator<<(ostream &os,vector> &v){for(vector &out:v){os<>n; vector

waza(n+1); for(int i=2;i<=n;i++){ ll l,a;cin>>l>>a; waza[i]={l,a}; } waza[1]={0,0}; // waza[0]={0,-1}; vector> nxtWaza(n+1); for(int i=2;i<=n;i++){ auto [l,a]=waza[i]; nxtWaza[a].push_back({l,i}); } const ll INF=1e15; vll lowerLv(n+1,INF); // lowerLv[i]:=技iを覚えるのに必要な最小レベル lowerLv[0]=-1; auto dfs=[&](auto f,int now,ll lv)->void{ // 技nowを覚える lowerLv[now]=lv; for(auto [l,nxt]:nxtWaza[now]){ f(f,nxt,max(lv,l)); } }; dfs(dfs,1,0); vll cp=lowerLv; cp[0]=INF; Sort(cp); int q;cin>>q; rep(_,q) { ll c,x;cin>>c>>x; if(c==1){ int res=upper_bound(cp.begin(),cp.end(),x)-cp.begin(); // res--; cout<< res <<'\n'; }else{ if(lowerLv[x]!=INF) cout<< lowerLv[x] <<'\n'; else cout<< -1 <<'\n'; } } return 0; }