// I SELL YOU...! #include #include #include #include #include #include #include #include #include using namespace std; using ll = int; using P = pair; using TP = tuple; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } ll calc(int i, vector &dp, vector &a, vector> &G, vector &arr) { if (dp[i] != -1) return dp[i]; if (arr[i]) { return dp[i] = -2; } arr[i] = 1; ll tmp = a[i]; for(auto nv: G[i]) { ll res = calc(nv, dp, a, G, arr); if (res == -2) { tmp = res; break; } tmp = max(res, tmp); } arr[i] = 0; return dp[i] = tmp; } signed main(){ init_io(); ll n; cin >> n; vector a(n); vector> G(n, vector()); vector found(n, false); vector dp(n, -1); vector arr(n, 0); a[0] = 0; dp[0] = 0; for (int i=1;i> y >> x; x--; G[i].push_back(x); a[i] = y; } vector copy; map mp; copy.push_back(0); for (int i=1;i> q; for (int i=0;i> x >> y; if (x == 1) { auto itr = mp.upper_bound(y); itr--; cout << itr->second << endl; } if (x == 2) { if (dp[y-1] == -2) dp[y-1] = -1; cout << dp[y-1] << endl; } } }