結果

問題 No.2325 Skill Tree
ユーザー gyozasukisukigyozasukisuki
提出日時 2023-05-28 16:02:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,744 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 216,156 KB
実行使用メモリ 190,964 KB
最終ジャッジ日時 2023-08-27 13:39:37
合計ジャッジ時間 15,664 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 54 ms
10,200 KB
testcase_08 AC 68 ms
16,044 KB
testcase_09 AC 132 ms
27,060 KB
testcase_10 AC 176 ms
58,812 KB
testcase_11 AC 94 ms
18,660 KB
testcase_12 AC 191 ms
34,180 KB
testcase_13 AC 190 ms
34,144 KB
testcase_14 AC 283 ms
83,072 KB
testcase_15 AC 2,131 ms
190,964 KB
testcase_16 AC 169 ms
24,500 KB
testcase_17 AC 163 ms
24,640 KB
testcase_18 AC 182 ms
34,268 KB
testcase_19 AC 164 ms
24,428 KB
testcase_20 AC 483 ms
102,820 KB
testcase_21 AC 165 ms
24,504 KB
testcase_22 AC 204 ms
34,300 KB
testcase_23 AC 289 ms
63,564 KB
testcase_24 AC 187 ms
34,236 KB
testcase_25 AC 167 ms
24,524 KB
testcase_26 AC 189 ms
34,108 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
const int INF = 1e9;
using ll = long long;
using inv = vector<int>;
using stv = vector<string>;
using pint = pair<int,int>;
#define FOR(i,l,r) for(int i=(l); i<(r); i++)
#define rep(i,r) for(int i=0; i<(r); i++)
#define repl(i,r) for(long long i=0; i<(r); i++)
#define FORl(i,l,r) for(long long i=(l); i<(r); i++)
#define INFL ((1LL<<62)-(1LL<<31))
#define pb(x) push_back(x)
#define CIN(x) cin >> x

// to and cost
using Graph = vector<vector<pair<ll,ll>>>;

void dfs(Graph G,int v,ll nowlv, vector<ll> &lv, vector<bool> &seen){
  seen[v] = true;
  lv[v] = nowlv;
  if(G[v].size() == 0) return;
  
  for(auto [nexv,l] : G[v]){
    if(seen[nexv]) continue;
    dfs(G,nexv,max(nowlv,l),lv,seen);
  }

}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  Graph G(N,vector<pair<ll,ll>>());
  G.reserve(2*1e5);

  vector<ll> minl(N,-1LL);
  minl.reserve(2*1e5);

  vector<bool> seen(N,false);
  seen.reserve(2*1e5);
  
  seen[0] = true;

  rep(i,N-1){
    ll L,A;
    cin >> L >> A;
    A--;
    G[A].pb(make_pair(i+1,L));
  }

  dfs(G,0,1,minl,seen);

  // rep(i,N) cout << minl[i] << " ";
  // cout<< endl;

  vector<ll> smin;
  smin.reserve(2*1e5);

  smin = minl;
  sort(smin.begin(),smin.end());
  ll cnt = (ll)(upper_bound(smin.begin(),smin.end(),-1)-smin.begin());


  int Q;
  cin >> Q;
  rep(q,Q){
    int t;
    cin >> t;
    if(t == 1){
      ll x;
      cin >> x;

      ll ans= (ll)(upper_bound(smin.begin(),smin.end(),x)-smin.begin());
      ans -= cnt;
      
      cout << ans << "\n";

    }else{
      int y;
      cin >> y;
      y--;
      cout << minl[y] << "\n";
    }
  }

  return 0;
}
0