結果

問題 No.2325 Skill Tree
ユーザー m_99m_99
提出日時 2023-05-28 13:43:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 627 ms / 3,000 ms
コード長 1,134 bytes
コンパイル時間 5,088 ms
コンパイル使用メモリ 271,956 KB
実行使用メモリ 17,060 KB
最終ジャッジ日時 2023-08-27 08:20:29
合計ジャッジ時間 25,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 265 ms
5,028 KB
testcase_08 AC 177 ms
8,752 KB
testcase_09 AC 298 ms
6,732 KB
testcase_10 AC 225 ms
12,388 KB
testcase_11 AC 303 ms
9,340 KB
testcase_12 AC 551 ms
16,136 KB
testcase_13 AC 551 ms
16,224 KB
testcase_14 AC 548 ms
16,180 KB
testcase_15 AC 552 ms
16,140 KB
testcase_16 AC 545 ms
16,244 KB
testcase_17 AC 541 ms
16,220 KB
testcase_18 AC 542 ms
16,244 KB
testcase_19 AC 538 ms
16,156 KB
testcase_20 AC 549 ms
16,136 KB
testcase_21 AC 545 ms
16,176 KB
testcase_22 AC 552 ms
16,252 KB
testcase_23 AC 550 ms
16,204 KB
testcase_24 AC 556 ms
16,252 KB
testcase_25 AC 551 ms
16,204 KB
testcase_26 AC 556 ms
16,308 KB
testcase_27 AC 625 ms
16,392 KB
testcase_28 AC 623 ms
16,636 KB
testcase_29 AC 621 ms
16,300 KB
testcase_30 AC 619 ms
16,476 KB
testcase_31 AC 618 ms
16,388 KB
testcase_32 AC 603 ms
17,060 KB
testcase_33 AC 621 ms
16,300 KB
testcase_34 AC 602 ms
16,336 KB
testcase_35 AC 623 ms
16,612 KB
testcase_36 AC 620 ms
16,928 KB
testcase_37 AC 627 ms
16,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	
	int n;
	cin>>n;
	vector E(n,vector<pair<int,long long>>());
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		b--;
		E[b].emplace_back(i+1,a);
	}
	
	vector<long long> d(n,Inf64);
	d[0] = 0;
	priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
	Q.emplace(0,0);
	while(Q.size()>0){
		long long D = Q.top().first;
		int u = Q.top().second;
		Q.pop();
		if(d[u]!=D)continue;
		rep(i,E[u].size()){
			int v = E[u][i].first;
			long long nD = max(D,(long long)E[u][i].second);
			if(d[v]>nD){
				d[v] = nD;
				Q.emplace(nD,v);
			}
		}
	}

	vector<long long> dd = d;
	sort(dd.begin(),dd.end());
	int q;
	cin>>q;
	rep(_,q){
		int t,x;
		cin>>t>>x;
		if(t==1){
			cout<<distance(dd.begin(),upper_bound(dd.begin(),dd.end(),x))<<endl;
		}
		else{
			long long ans = d[x-1];
			if(ans==Inf64)ans = -1;
			cout<<ans<<endl;
		}
	}
	
	return 0;
}
0