結果

問題 No.2325 Skill Tree
ユーザー suisanka12suisanka12
提出日時 2023-05-28 14:26:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 3,000 ms
コード長 2,540 bytes
コンパイル時間 3,547 ms
コンパイル使用メモリ 177,648 KB
実行使用メモリ 15,084 KB
最終ジャッジ日時 2023-08-27 09:46:54
合計ジャッジ時間 11,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 38 ms
4,676 KB
testcase_08 AC 42 ms
8,068 KB
testcase_09 AC 49 ms
6,456 KB
testcase_10 AC 66 ms
11,148 KB
testcase_11 AC 59 ms
8,812 KB
testcase_12 AC 122 ms
14,724 KB
testcase_13 AC 119 ms
14,840 KB
testcase_14 AC 121 ms
14,836 KB
testcase_15 AC 124 ms
14,912 KB
testcase_16 AC 122 ms
14,768 KB
testcase_17 AC 112 ms
14,704 KB
testcase_18 AC 112 ms
14,828 KB
testcase_19 AC 112 ms
15,060 KB
testcase_20 AC 118 ms
14,840 KB
testcase_21 AC 114 ms
14,776 KB
testcase_22 AC 125 ms
14,768 KB
testcase_23 AC 127 ms
14,752 KB
testcase_24 AC 127 ms
15,084 KB
testcase_25 AC 129 ms
14,768 KB
testcase_26 AC 128 ms
14,776 KB
testcase_27 AC 160 ms
13,924 KB
testcase_28 AC 159 ms
13,976 KB
testcase_29 AC 158 ms
13,972 KB
testcase_30 AC 163 ms
14,076 KB
testcase_31 AC 162 ms
13,972 KB
testcase_32 AC 147 ms
14,044 KB
testcase_33 AC 151 ms
14,264 KB
testcase_34 AC 148 ms
13,988 KB
testcase_35 AC 156 ms
14,032 KB
testcase_36 AC 153 ms
13,992 KB
testcase_37 AC 157 ms
14,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
constexpr int MD = 1000000007;
constexpr int INF = INT_MAX;
constexpr long long LINF = LLONG_MAX;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;using vi = vector<int>;using vll = vector<ll>;
template <class T>
using ps = pair<T, T>;
template <class T>
using vec = vector<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;  // ascendent

template <typename T>
int sz(const T& x) { return x.size(); }

// a = min(a,b)
template <typename T, typename S>
inline bool chmin(T& a, const S& b) {
  return (a > b ? a = b, 1 : 0);
}
template <typename T, typename S>
inline bool chmax(T& a, const S& b) {
  return (a < b ? a = b, 1 : 0);
}

ll mpow(int base, int exponent, int mod){
    if(exponent == 0) return 1;
    ll c = mpow(base, exponent/2, mod);
    c *= c;
    c %= mod;
    if(exponent % 2 == 1){
        c *= base;
        c %= mod;
    }
    return c;
}

/* 
auto push = [&](int r, int c){
    if(r < 0 || c < 0 || r >= h || c >= w) return;
    if(dist[r][c] != -1) return;
};
*/ //dfs/bfs埋め込み用

/*
class edge{
public:
    int to, weight;
    edge(int a, int b){
        to = a; weight = b;
    }
};
*/ //template of edge
/*class edge2{
public:
    int from, to, weight;
    edge2(int w, int a, int b){
        from = w; to = a; weight = b;
    }
};
bool comp(edge2 a, edge2 b){
    return a.weight < b.weight;
}
*/ //template of edge2
struct before_main_function {
  before_main_function() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << setprecision(20) << fixed;
#define endl "\n"
  }
} before_main_function;
vec<int > d, l;
vec<vec<int>> g;
void dfs(int p){
  for(auto it : g[p]){
    d[it] = max(d[p], l[it]);
    dfs(it);
  }
}
int main(int /*argc*/, char** /*argv*/){
  int n;
  std::cin >> n;
  vec<int> a(n);
  l.resize(n);
  l[0] = 0; a[0] = 0;
  REP(i, n-1) std::cin >> l[i+1] >> a[i+1];
  g.resize(n);
  REP(i, n-1){
    g[a[i+1]-1].emplace_back(i+1);
  }
  //d[i] iをするために必要なレベル
  d.resize(n, INF);
  d[0] = 0;
  dfs(0);
  int q;
  std::cin >> q;
  vec<int> st = d;
  sort(st.begin(), st.end());
  REP(i, q){
    int typ, x;
    std::cin >> typ >> x;
    if(typ == 1){
      //レベルxが覚えられる最大値
      auto it = upper_bound(st.begin(), st.end(), x)-st.begin();
      std::cout << it << endl;
    }
    else{
      if(d[x-1] == INF) std::cout << "-1\n";
      else std::cout << d[x-1] << endl;
    }
  }
  return 0;
}
0