結果

問題 No.2325 Skill Tree
ユーザー 👑 emthrmemthrm
提出日時 2023-05-28 13:57:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 3,000 ms
コード長 1,747 bytes
コンパイル時間 3,434 ms
コンパイル使用メモリ 263,784 KB
実行使用メモリ 13,576 KB
最終ジャッジ日時 2023-08-27 08:43:33
合計ジャッジ時間 11,199 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 42 ms
7,292 KB
testcase_09 AC 50 ms
5,960 KB
testcase_10 AC 67 ms
10,064 KB
testcase_11 AC 61 ms
7,952 KB
testcase_12 AC 125 ms
13,232 KB
testcase_13 AC 124 ms
13,240 KB
testcase_14 AC 126 ms
13,232 KB
testcase_15 AC 125 ms
13,284 KB
testcase_16 AC 126 ms
13,240 KB
testcase_17 AC 123 ms
13,164 KB
testcase_18 AC 124 ms
13,280 KB
testcase_19 AC 125 ms
13,212 KB
testcase_20 AC 122 ms
13,160 KB
testcase_21 AC 122 ms
13,208 KB
testcase_22 AC 127 ms
13,176 KB
testcase_23 AC 125 ms
13,224 KB
testcase_24 AC 124 ms
13,300 KB
testcase_25 AC 121 ms
13,300 KB
testcase_26 AC 124 ms
13,132 KB
testcase_27 AC 155 ms
13,384 KB
testcase_28 AC 155 ms
13,520 KB
testcase_29 AC 153 ms
13,448 KB
testcase_30 AC 155 ms
13,460 KB
testcase_31 AC 152 ms
13,544 KB
testcase_32 AC 143 ms
13,480 KB
testcase_33 AC 143 ms
13,460 KB
testcase_34 AC 146 ms
13,492 KB
testcase_35 AC 153 ms
13,484 KB
testcase_36 AC 152 ms
13,576 KB
testcase_37 AC 163 ms
13,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> l(n, 0);
  vector<vector<int>> graph(n);
  FOR(i, 1, n) {
    int a; cin >> l[i] >> a; --a;
    graph[a].emplace_back(i);
  };
  vector<int> level(n, INF);
  level[0] = 0;
  queue<int> que({0});
  while (!que.empty()) {
    const int skill = que.front(); que.pop();
    for (const int e : graph[skill]) {
      level[e] = max(l[e], level[skill]);
      que.emplace(e);
    }
  }
  vector<int> can_rem;
  REP(i, n) {
    if (level[i] != INF) can_rem.emplace_back(level[i]);
  }
  ranges::sort(can_rem);
  int q; cin >> q;
  while (q--) {
    int type; cin >> type;
    if (type == 1) {
      int x; cin >> x;
      cout << distance(can_rem.begin(), ranges::upper_bound(can_rem, x)) << '\n';
    } else if (type == 2) {
      int y; cin >> y; --y;
      cout << (level[y] == INF ? -1 : level[y]) << '\n';
    }
  }
  return 0;
}
0