#include using namespace std; typedef long long ll; vector>> g; vector vis; int N; int dfs(int c,int ml,int last){ 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); if(ans != -1){ break; } } return ans; } int solve(){ int x,y; cin >> x >> y; if(x == 1){ deque co; ll ans=1; co.push_back(0); while(!co.empty()){ int p=co.front(); co.pop_front(); vis[p] = true; for(auto next:g[p]){ if(next.second<=y && !vis[next.first]){ ans++; co.push_back(next.first); vis[next.first] = true; } } } for(int i=0;i> N; vis.resize(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