// I SELL YOU...! #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; 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) { if (dp[i] != -1) return dp[i]; ll tmp = a[i]; for(auto nv: G[i]) { tmp = max(tmp, calc(nv, dp, a, G)); } return dp[i] = tmp; } signed main(){ init_io(); ll n; cin >> n; vector a(n); vector> G(n, vector()); int is_cicle = true; a[0] = 0; vector dp(n, -1); dp[0] = 0; for (int i=1;i> y >> x; if (x == 1) is_cicle = false; x--; G[i].push_back(x); a[i] = y; } map mp; mp[0]++; vector copy(n); copy[0] = 0; if (!is_cicle) { for (int i=1;i> q; for (int i=0;i> x >> y; if (x == 1) { if (is_cicle) { cout << 1 << endl; } else { auto itr = mp.upper_bound(y); itr--; cout << itr->second << endl; } } if (x == 2) { cout << dp[y-1] << endl; } } }