結果

問題 No.2325 Skill Tree
ユーザー k82bk82b
提出日時 2023-05-28 14:59:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 455 ms / 3,000 ms
コード長 873 bytes
コンパイル時間 3,115 ms
コンパイル使用メモリ 212,940 KB
実行使用メモリ 18,436 KB
最終ジャッジ日時 2023-08-27 11:05:31
合計ジャッジ時間 17,839 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 209 ms
5,060 KB
testcase_08 AC 122 ms
9,384 KB
testcase_09 AC 227 ms
7,232 KB
testcase_10 AC 144 ms
13,544 KB
testcase_11 AC 224 ms
10,680 KB
testcase_12 AC 392 ms
18,268 KB
testcase_13 AC 387 ms
18,228 KB
testcase_14 AC 388 ms
18,188 KB
testcase_15 AC 402 ms
18,316 KB
testcase_16 AC 395 ms
18,296 KB
testcase_17 AC 390 ms
18,256 KB
testcase_18 AC 390 ms
18,436 KB
testcase_19 AC 395 ms
18,416 KB
testcase_20 AC 397 ms
18,384 KB
testcase_21 AC 393 ms
18,140 KB
testcase_22 AC 388 ms
18,212 KB
testcase_23 AC 385 ms
18,256 KB
testcase_24 AC 386 ms
18,196 KB
testcase_25 AC 393 ms
18,304 KB
testcase_26 AC 389 ms
18,224 KB
testcase_27 AC 455 ms
17,668 KB
testcase_28 AC 441 ms
17,760 KB
testcase_29 AC 440 ms
17,956 KB
testcase_30 AC 438 ms
18,008 KB
testcase_31 AC 443 ms
17,664 KB
testcase_32 AC 429 ms
17,976 KB
testcase_33 AC 429 ms
17,668 KB
testcase_34 AC 425 ms
17,668 KB
testcase_35 AC 437 ms
17,780 KB
testcase_36 AC 430 ms
17,788 KB
testcase_37 AC 442 ms
17,808 KB
権限があれば一括ダウンロードができます

ソースコード

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