結果

問題 No.2325 Skill Tree
ユーザー srpkdyysrpkdyy
提出日時 2023-05-28 15:23:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 4,220 ms
コンパイル使用メモリ 232,796 KB
実行使用メモリ 9,628 KB
最終ジャッジ日時 2024-06-08 07:39:48
合計ジャッジ時間 18,809 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 166 ms
7,648 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 390 ms
9,512 KB
testcase_18 WA -
testcase_19 AC 383 ms
9,496 KB
testcase_20 WA -
testcase_21 AC 399 ms
9,368 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 392 ms
9,496 KB
testcase_25 AC 413 ms
9,516 KB
testcase_26 WA -
testcase_27 AC 409 ms
9,496 KB
testcase_28 AC 425 ms
9,492 KB
testcase_29 AC 410 ms
9,444 KB
testcase_30 AC 404 ms
9,492 KB
testcase_31 AC 401 ms
9,500 KB
testcase_32 AC 403 ms
9,496 KB
testcase_33 AC 401 ms
9,496 KB
testcase_34 AC 389 ms
9,496 KB
testcase_35 AC 405 ms
9,496 KB
testcase_36 AC 422 ms
9,496 KB
testcase_37 AC 415 ms
9,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i=0; i<(n); i++)
#define len(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using namespace atcoder;
using ll = long long;
using mint9 = atcoder::modint998244353;
using mint10 = atcoder::modint1000000007;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);

   int N;
   cin >> N;
   vector<ll> L(N), A(N);
   L[0] = 1;
   A[0] = 0;
   rep(i, N-1) {
      cin >> L[i+1] >> A[i+1];
      A[i+1]--;
   }

   rep(i, 60) {
      auto B = A;
      auto M = L;
      rep(j, N) {
         B[j] = A[A[j]];
         M[j] = max(L[j], L[A[j]]);
      }
      swap(A, B);
      swap(L, M);
   }

   rep(i, N) {
      if (A[i] != A[A[i]]) L[i] = numeric_limits<ll>::max();
   }

   auto S = L;
   sort(all(S));

   int Q;
   cin >> Q;
   vector<ll> ans(Q);
   rep(i, Q) {
      int op, z;
      cin >> op >> z;
      if (op == 1) {
         ans[i] = upper_bound(all(S), z) - S.begin();
      }
      else {
         z--;
         if (A[z] != A[A[z]])  ans[i] = -1;
         else ans[i] = L[z];
      }
   }
   rep(i, Q) cout << ans[i] << endl;
   return 0;
}

0