#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; vector mx; vector visit; void dfs(vector> &E, int from, int p){ visit[from] = 1; for(auto to : E[from]){ if (p == to) continue; mx[to] = max(mx[from], mx[to]); dfs(E, to, from); } } int main(){ int N, Q, t, x, L, A; cin >> N; vector> E(N); mx.resize(N); visit.resize(N); for (int i=1; i> L >> A; A--; mx[i] = L; E[A].push_back(i); } dfs(E, 0, -1); vector lv; for (int i=0; i> Q; while(Q){ Q--; cin >> t >> x; if (t == 1) cout << upper_bound(lv.begin(), lv.end(), x) - lv.begin() << endl; else cout << (visit[x-1] ? mx[x-1] : -1) << endl; } return 0; }