#include using namespace std; typedef long long ll; vector>> g; int N; int dfs(int c,int ml,int last,map vis){ if(c == last){ return ml; } int ans=-1; vis[c] = true; for(auto next : g[c]){ if(vis[next.first]){ continue; } ans = dfs(next.first,max(ml,next.second), last,vis); if(ans != -1){ break; } } return ans; } int ans2; void dfs2(int c, int ml,map vis){ vis[c] = true; for(auto next : g[c]){ if(vis[next.first]){ continue; } if(next.second<=ml){ dfs2(next.first, ml,vis); ans2++; } } } int solve(){ int x,y; cin >> x >> y; map vis; if(x == 1){ ans2=0; dfs2(0,y,vis); return ans2; }else{ ll ans = dfs(0,1,y-1,vis); return ans; } } int main(){ cin >> N; g.resize(N); for(int i=1;i> L >> A; A--; g[A].push_back({i,L}); g[i].push_back({A,L}); } int Q; cin >> Q; for(int i=0;i