結果

問題 No.2325 Skill Tree
ユーザー gyozasukisukigyozasukisuki
提出日時 2023-05-28 15:21:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,425 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 209,868 KB
実行使用メモリ 16,080 KB
最終ジャッジ日時 2023-08-27 12:01:07
合計ジャッジ時間 13,408 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2,313 ms
9,876 KB
testcase_08 AC 2,928 ms
16,080 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
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,(nowlv > l ? nowlv:l),lv,seen);
  }

}

int main(){
  ll N;
  cin >> N;
  Graph G(N,vector<pair<ll,ll>>());

  vector<ll> minl(N,-1LL);
  vector<bool> seen(N,false);
  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;


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

      ll ans= 0;
      rep(i,N) if(minl[i] != -1 && minl[i] <= x) ans++;
      cout << ans << endl;

    }else{
      int y;
      cin >> y;
      y--;
      cout << minl[y] << endl;
    }
  }

}
0