結果

問題 No.2325 Skill Tree
ユーザー Taiki0715Taiki0715
提出日時 2023-05-28 14:06:56
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 595 ms / 3,000 ms
コード長 1,863 bytes
コンパイル時間 3,509 ms
コンパイル使用メモリ 167,288 KB
実行使用メモリ 13,624 KB
最終ジャッジ日時 2024-12-26 23:29:27
合計ジャッジ時間 23,324 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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