結果
| 問題 | 
                            No.2325 Skill Tree
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-05-28 15:19:52 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,195 bytes | 
| コンパイル時間 | 4,095 ms | 
| コンパイル使用メモリ | 234,812 KB | 
| 実行使用メモリ | 9,628 KB | 
| 最終ジャッジ日時 | 2024-12-27 06:02:56 | 
| 合計ジャッジ時間 | 19,277 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 21 WA * 15 | 
ソースコード
#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, 30) {
      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;
}