結果

問題 No.2325 Skill Tree
ユーザー FplusFplusFFplusFplusF
提出日時 2023-05-28 14:24:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 3,000 ms
コード長 1,355 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 213,596 KB
実行使用メモリ 15,292 KB
最終ジャッジ日時 2023-08-27 09:43:08
合計ジャッジ時間 10,604 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 38 ms
4,748 KB
testcase_08 AC 45 ms
7,528 KB
testcase_09 AC 51 ms
5,884 KB
testcase_10 AC 72 ms
10,420 KB
testcase_11 AC 66 ms
8,388 KB
testcase_12 AC 133 ms
13,512 KB
testcase_13 AC 125 ms
13,424 KB
testcase_14 AC 129 ms
13,388 KB
testcase_15 AC 130 ms
13,400 KB
testcase_16 AC 129 ms
13,372 KB
testcase_17 AC 125 ms
13,452 KB
testcase_18 AC 123 ms
13,584 KB
testcase_19 AC 124 ms
13,544 KB
testcase_20 AC 124 ms
13,588 KB
testcase_21 AC 121 ms
13,556 KB
testcase_22 AC 128 ms
13,552 KB
testcase_23 AC 136 ms
13,496 KB
testcase_24 AC 133 ms
13,604 KB
testcase_25 AC 132 ms
13,492 KB
testcase_26 AC 130 ms
13,656 KB
testcase_27 AC 176 ms
14,984 KB
testcase_28 AC 177 ms
14,992 KB
testcase_29 AC 173 ms
15,136 KB
testcase_30 AC 173 ms
15,144 KB
testcase_31 AC 180 ms
15,076 KB
testcase_32 AC 160 ms
15,208 KB
testcase_33 AC 165 ms
15,292 KB
testcase_34 AC 163 ms
14,988 KB
testcase_35 AC 171 ms
14,996 KB
testcase_36 AC 171 ms
14,984 KB
testcase_37 AC 175 ms
15,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
vector<vector<ll>> g;
vector<ll> l;
vector<bool> vis;
void dfs(ll x,ll m){
    for(auto &i:g[x]){
        if(vis[i]) continue;
        vis[i]=true;
        chmax(l[i],m);
        dfs(i,l[i]);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    g.resize(n);
    l.resize(n);
    l[0]=1;
    rep(i,n-1){
        ll a;
        cin >> l[i+1] >> a;
        a--;
        g[a].push_back(i+1);
    }
    vis.resize(n,false);
    vis[0]=true;
    dfs(0,1);
    vector<ll> v;
    rep(i,n){
        if(!vis[i]) continue;
        v.push_back(l[i]);
    }
    sort(all(v));
    ll q;
    cin >> q;
    while(q--){
        ll t;
        cin >> t;
        if(t==1){
            ll x;
            cin >> x;
            cout << (ll)(upper_bound(all(v),x)-v.begin()) << '\n';
        }
        if(t==2){
            ll y;
            cin >> y;
            y--;
            if(!vis[y]) cout << "-1\n";
            else cout << l[y] << '\n';
        }
    }
}
0