結果

問題 No.2325 Skill Tree
ユーザー umezoumezo
提出日時 2023-05-28 14:19:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 3,000 ms
コード長 1,126 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 210,140 KB
実行使用メモリ 18,084 KB
最終ジャッジ日時 2023-08-27 09:30:10
合計ジャッジ時間 11,002 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,040 KB
testcase_01 AC 4 ms
8,128 KB
testcase_02 AC 4 ms
8,136 KB
testcase_03 AC 4 ms
8,292 KB
testcase_04 AC 4 ms
8,084 KB
testcase_05 AC 5 ms
8,016 KB
testcase_06 AC 4 ms
8,116 KB
testcase_07 AC 42 ms
9,512 KB
testcase_08 AC 51 ms
11,436 KB
testcase_09 AC 55 ms
10,088 KB
testcase_10 AC 82 ms
13,996 KB
testcase_11 AC 71 ms
11,988 KB
testcase_12 AC 143 ms
16,408 KB
testcase_13 AC 148 ms
16,428 KB
testcase_14 AC 150 ms
16,480 KB
testcase_15 AC 149 ms
16,368 KB
testcase_16 AC 145 ms
16,448 KB
testcase_17 AC 147 ms
16,660 KB
testcase_18 AC 140 ms
16,412 KB
testcase_19 AC 147 ms
16,344 KB
testcase_20 AC 147 ms
16,376 KB
testcase_21 AC 143 ms
16,400 KB
testcase_22 AC 145 ms
16,360 KB
testcase_23 AC 148 ms
16,584 KB
testcase_24 AC 148 ms
16,372 KB
testcase_25 AC 147 ms
16,344 KB
testcase_26 AC 149 ms
16,496 KB
testcase_27 AC 204 ms
18,056 KB
testcase_28 AC 198 ms
18,084 KB
testcase_29 AC 191 ms
17,900 KB
testcase_30 AC 198 ms
17,824 KB
testcase_31 AC 190 ms
17,920 KB
testcase_32 AC 172 ms
17,572 KB
testcase_33 AC 177 ms
18,052 KB
testcase_34 AC 187 ms
18,028 KB
testcase_35 AC 192 ms
17,720 KB
testcase_36 AC 183 ms
17,416 KB
testcase_37 AC 202 ms
18,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> G[200200];
const int INF=1e9+7;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  vector<int> L(n),A(n);
  for(int i=1;i<n;i++){
    cin>>L[i]>>A[i];
    A[i]--;
    G[i].push_back(A[i]);
    G[A[i]].push_back(i);
  }
  vector<int> P(n,INF);
  
  auto dfs=[&](auto dfs,int v,int p,int d)->void{
    d=max(d,L[v]);
    P[v]=d;
    for(auto nv:G[v]){
      if(nv==p) continue;
      dfs(dfs,nv,v,d);
    }
  };
  
  dfs(dfs,0,-1,0);
  map<int,int> m;
  rep(i,n) m[P[i]]++;
  int k=m.size();
  vector<int> B,C;
  for(auto [b,c]:m){
    B.push_back(b);
    C.push_back(c);
  }
  vector<int> S(k);
  S[0]=C[0];
  for(int i=1;i<k;i++) S[i]=S[i-1]+C[i];
  
  int q;
  cin>>q;
  while(q--){
    int c,x;
    cin>>c>>x;
    if(c==1){
      auto a=upper_bound(ALL(B),x)-B.begin();
      a--;
      cout<<S[a]<<'\n';
    }
    else{
      x--;
      if(P[x]==INF) cout<<-1<<'\n';
      else cout<<P[x]<<'\n';
    }
  }

  return 0;
}
0