結果

問題 No.2325 Skill Tree
ユーザー cho435cho435
提出日時 2023-05-28 14:04:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 727 ms / 3,000 ms
コード長 848 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 209,508 KB
実行使用メモリ 14,812 KB
最終ジャッジ日時 2023-08-27 08:58:35
合計ジャッジ時間 22,697 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 262 ms
4,516 KB
testcase_08 AC 169 ms
7,552 KB
testcase_09 AC 290 ms
6,276 KB
testcase_10 AC 209 ms
10,568 KB
testcase_11 AC 292 ms
8,264 KB
testcase_12 AC 533 ms
13,992 KB
testcase_13 AC 529 ms
14,228 KB
testcase_14 AC 529 ms
14,132 KB
testcase_15 AC 531 ms
14,080 KB
testcase_16 AC 527 ms
14,072 KB
testcase_17 AC 523 ms
13,948 KB
testcase_18 AC 529 ms
14,116 KB
testcase_19 AC 516 ms
13,992 KB
testcase_20 AC 518 ms
13,880 KB
testcase_21 AC 727 ms
14,064 KB
testcase_22 AC 531 ms
14,056 KB
testcase_23 AC 533 ms
14,300 KB
testcase_24 AC 534 ms
14,292 KB
testcase_25 AC 536 ms
14,004 KB
testcase_26 AC 538 ms
14,000 KB
testcase_27 AC 595 ms
14,324 KB
testcase_28 AC 596 ms
14,224 KB
testcase_29 AC 601 ms
14,352 KB
testcase_30 AC 592 ms
14,576 KB
testcase_31 AC 592 ms
14,272 KB
testcase_32 AC 571 ms
14,700 KB
testcase_33 AC 572 ms
14,188 KB
testcase_34 AC 569 ms
14,456 KB
testcase_35 AC 593 ms
14,532 KB
testcase_36 AC 590 ms
14,812 KB
testcase_37 AC 601 ms
14,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)

int main(){
  int n;
  cin>>n;
  vector<int> l(n,0),a(n,0);
  rep(i,n-1) cin>>l.at(i+1)>>a.at(i+1);
  rep(i,n) a.at(i)--;
  vector<vector<int>> g(n);
  rep(i,n-1){
    g.at(a.at(i+1)).push_back(i+1);
  }
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
  pq.push({0,0});
  vector<int> q1;
  vector<int> q2(n,-1);
  while(!pq.empty()){
    auto [lv,nw]=pq.top();
    pq.pop();
    q2.at(nw)=lv;
    q1.push_back(lv);
    for(int nx:g.at(nw)){
      pq.push({max(lv,l.at(nx)),nx});
    }
  }
  int q;
  cin>>q;
  rep(Qi,q){
    int t,x;
    cin>>t>>x;
    if(t==1){
      int ans=upper_bound(q1.begin(),q1.end(),x)-q1.begin();
      cout<<ans<<'\n';
    }else{
      cout<<q2.at(x-1)<<'\n';
    }
  }
}
0