#include #include using namespace std; using namespace atcoder; // type typedef long long ll; typedef long double ld; template using pq = priority_queue; template using pqg = priority_queue, greater>; template using v = vector; #define pl pair #define vl v #define vp v #define vm v // IN-OUT #define NYAN ios::sync_with_stdio(false);cin.tie(nullptr);cout< void CIN(T &t, U &...u) { cin >> t; CIN(u...); } void COUT() { cout << "\n"; } template void COUT(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; COUT(u...); } #define dump(x) cerr << #x << ":"<< x << "\n"; #define vdump(x) rep(repeat, sz(x)) cerr << repeat << ":" << x[repeat] << "\n"; // macro #define bp __builtin_popcountll #define ALL(x) x.begin(),x.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define reps(i, s, n) for (ll i = s; i < (ll)(n); i++) #define sz(x) (ll)x.size() ll xd[]={0, 1, 0, -1, 1, 1, -1, -1}; ll yd[]={1, 0, -1, 0, 1, -1, -1, 1}; // function templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; vl l(n), a(n); v edge(n); reps(i, 1, n){ cin >> l[i] >> a[i]; a[i]--; edge[a[i]].emplace_back(i); } vl L(n, -1); L[0] = 0; queue Q; Q.emplace(0); while(sz(Q)){ auto now = Q.front(); Q.pop(); for(auto next : edge[now]){ L[next] = max(L[now], l[next]); Q.emplace(next); } } map mp; rep(i, n) mp[L[i]]++; ll sum = 0; for(auto [f, s] : mp){ if(f == -1) continue; sum += s; mp[f] = sum; } ll q; cin >> q; while(q--){ ll op; cin >> op; ll x; cin >> x; if(op == 1){ auto it = mp.upper_bound(x); if(it == mp.begin()) cout << 0 << "\n"; else{ it--; auto [f, s] = *it; cout << s << "\n"; } }else{ x--; cout << L[x] << "\n"; } } } int main() { NYAN solve(); return 0; }