結果

問題 No.2325 Skill Tree
ユーザー k82b
提出日時 2023-05-28 14:59:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 384 ms / 3,000 ms
コード長 873 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 207,260 KB
最終ジャッジ日時 2025-02-13 12:21:08
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve();

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cout<<fixed<<setprecision(15);

	int T=1;

	//cin>>T;
	
	while(T--)solve();

	return 0;
}

void solve(){
	int N;cin>>N;
	vector<int>L(N),A(N);
	vector<vector<int>>G(N);
	for(int i=0;i<N-1;++i){
		cin>>L[i]>>A[i];
		A[i]--;
		G[A[i]].push_back(i+1);
	}
	queue<int>que;
	vector<int>e(N,-1);
	vector<int>c(N,2e9);
	que.push(0);
	e[0]=1;
	c[0]=1;
	while(!que.empty()){
		int u=que.front();que.pop();
		for(int v:G[u])if(e[v]==-1){
			e[v]=max(e[u],L[v-1]);
			c[v]=e[v];
			que.push(v);
		}
	}
	sort(c.begin(),c.end());
	int Q;cin>>Q;
	while(Q--){
		int type;cin>>type;
		if(type==1){
			int x;cin>>x;
			cout<<upper_bound(c.begin(),c.end(),x)-c.begin()<<endl;
		}
		if(type==2){
			int y;cin>>y;
			y--;
			cout<<e[y]<<endl;
		}
	}
}
0