結果

問題 No.2325 Skill Tree
ユーザー Taiki0715Taiki0715
提出日時 2023-05-28 14:06:56
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 599 ms / 3,000 ms
コード長 1,863 bytes
コンパイル時間 4,381 ms
コンパイル使用メモリ 131,488 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-08-27 09:04:28
合計ジャッジ時間 25,409 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 265 ms
4,472 KB
testcase_08 AC 176 ms
7,112 KB
testcase_09 AC 298 ms
5,812 KB
testcase_10 AC 227 ms
10,044 KB
testcase_11 AC 306 ms
7,960 KB
testcase_12 AC 563 ms
12,900 KB
testcase_13 AC 548 ms
12,808 KB
testcase_14 AC 550 ms
12,900 KB
testcase_15 AC 554 ms
12,848 KB
testcase_16 AC 557 ms
12,808 KB
testcase_17 AC 542 ms
12,852 KB
testcase_18 AC 543 ms
12,856 KB
testcase_19 AC 544 ms
12,800 KB
testcase_20 AC 544 ms
12,880 KB
testcase_21 AC 545 ms
12,824 KB
testcase_22 AC 559 ms
12,804 KB
testcase_23 AC 564 ms
12,768 KB
testcase_24 AC 557 ms
12,792 KB
testcase_25 AC 556 ms
12,788 KB
testcase_26 AC 559 ms
12,892 KB
testcase_27 AC 588 ms
13,340 KB
testcase_28 AC 591 ms
13,512 KB
testcase_29 AC 592 ms
13,336 KB
testcase_30 AC 582 ms
13,380 KB
testcase_31 AC 584 ms
13,380 KB
testcase_32 AC 561 ms
13,416 KB
testcase_33 AC 567 ms
13,344 KB
testcase_34 AC 571 ms
13,388 KB
testcase_35 AC 595 ms
13,400 KB
testcase_36 AC 599 ms
13,548 KB
testcase_37 AC 599 ms
13,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cassert>
#include <bitset>
#include <map>
#include <algorithm>
#include <iterator>
#include <string>
#include <utility>
#include <numeric>
#include <regex>
#include <complex>
#include <random>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
  is>>p.first>>p.second;
  return is;
}
template<typename T>
istream &operator>>(istream &is,vector<T> &a){
  for(auto &i:a)is>>i;
  return is;
}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
ll myceil(ll a,ll b){return (a+b-1)/b;}
int main(){
  int n;
  cin>>n;
  vector<vector<pair<int,int>>>to(n);
  rep(i,n-1){
    int l,a;
    cin>>l>>a;
    a--;
    to[a].push_back({l,i+1});
  }
  vector<int>ans(n,-1);
  ans[0]=0;
  queue<int>que;
  que.push(0);
  while(!que.empty()){
    int x=que.front();
    que.pop();
    for(auto i:to[x]){
      if(chmax(ans[i.second],max(ans[x],i.first))){
        que.push(i.second);
      }
    }
  }
  vector<int>c;
  rep(i,n){
    if(ans[i]!=-1)c.push_back(ans[i]);
  }
  sort(all(c));
  int q;
  cin>>q;
  while(q--){
    int t,x;
    cin>>t>>x;
    if(t==1){
      cout<<(upper_bound(all(c),x)-c.begin())<<endl;
    }
    else{
      cout<<ans[x-1]<<endl;
    }
  }
}
0