結果

問題 No.2325 Skill Tree
ユーザー kotatsugamekotatsugame
提出日時 2023-05-28 13:43:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 625 ms / 3,000 ms
コード長 890 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 83,584 KB
実行使用メモリ 15,124 KB
最終ジャッジ日時 2023-08-27 08:20:03
合計ジャッジ時間 21,057 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,528 KB
testcase_01 AC 5 ms
9,468 KB
testcase_02 AC 5 ms
9,792 KB
testcase_03 AC 4 ms
9,540 KB
testcase_04 AC 4 ms
9,672 KB
testcase_05 AC 4 ms
9,528 KB
testcase_06 AC 5 ms
9,472 KB
testcase_07 AC 265 ms
10,308 KB
testcase_08 AC 176 ms
11,556 KB
testcase_09 AC 297 ms
10,864 KB
testcase_10 AC 223 ms
13,080 KB
testcase_11 AC 303 ms
11,832 KB
testcase_12 AC 549 ms
15,124 KB
testcase_13 AC 545 ms
14,952 KB
testcase_14 AC 549 ms
14,896 KB
testcase_15 AC 546 ms
14,888 KB
testcase_16 AC 546 ms
14,828 KB
testcase_17 AC 542 ms
14,924 KB
testcase_18 AC 533 ms
14,748 KB
testcase_19 AC 533 ms
14,872 KB
testcase_20 AC 536 ms
14,940 KB
testcase_21 AC 527 ms
14,880 KB
testcase_22 AC 558 ms
14,960 KB
testcase_23 AC 551 ms
14,816 KB
testcase_24 AC 550 ms
14,880 KB
testcase_25 AC 558 ms
14,884 KB
testcase_26 AC 551 ms
14,812 KB
testcase_27 AC 621 ms
14,292 KB
testcase_28 AC 616 ms
14,292 KB
testcase_29 AC 611 ms
14,240 KB
testcase_30 AC 618 ms
14,300 KB
testcase_31 AC 615 ms
14,240 KB
testcase_32 AC 585 ms
13,980 KB
testcase_33 AC 595 ms
14,292 KB
testcase_34 AC 603 ms
14,424 KB
testcase_35 AC 611 ms
14,036 KB
testcase_36 AC 604 ms
14,024 KB
testcase_37 AC 625 ms
14,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cassert>
using namespace std;
int N,Q;
vector<int>G[2<<17];
int L[2<<17];
bool vis[2<<17];
int main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int A;
		cin>>L[i]>>A;
		G[A-1].push_back(i);
	}
	priority_queue<pair<int,int> >pq;
	pq.push(make_pair(0,0));
	while(!pq.empty())
	{
		int u=pq.top().second;
		int c=-pq.top().first;
		pq.pop();
		if(vis[u])continue;
		vis[u]=true;
		L[u]=max(L[u],c);
		for(int v:G[u])
		{
			assert(!vis[v]);
			pq.push(make_pair(-L[u],v));
		}
	}
	vector<int>Lv(N);
	for(int i=0;i<N;i++)
	{
		if(vis[i])Lv[i]=L[i];
		else Lv[i]=2e9;
	}
	sort(Lv.begin(),Lv.end());
	cin>>Q;
	for(;Q--;)
	{
		int op;cin>>op;
		if(op==1)
		{
			int x;cin>>x;
			cout<<upper_bound(Lv.begin(),Lv.end(),x)-Lv.begin()<<"\n";
		}
		else
		{
			int y;cin>>y;
			y--;
			cout<<(vis[y]?L[y]:-1)<<"\n";
		}
	}
}
0