結果

問題 No.2325 Skill Tree
ユーザー FplusFplusFFplusFplusF
提出日時 2023-05-28 14:23:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,337 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 210,308 KB
実行使用メモリ 15,284 KB
最終ジャッジ日時 2023-08-27 09:38:08
合計ジャッジ時間 9,401 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 45 ms
7,604 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 65 ms
8,272 KB
testcase_12 AC 129 ms
13,604 KB
testcase_13 AC 129 ms
13,552 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 127 ms
13,464 KB
testcase_17 AC 122 ms
13,412 KB
testcase_18 AC 119 ms
13,488 KB
testcase_19 AC 122 ms
13,528 KB
testcase_20 AC 121 ms
13,528 KB
testcase_21 AC 119 ms
13,684 KB
testcase_22 AC 132 ms
13,412 KB
testcase_23 WA -
testcase_24 AC 131 ms
13,472 KB
testcase_25 AC 127 ms
13,464 KB
testcase_26 AC 130 ms
13,556 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 141 ms
15,012 KB
testcase_33 AC 141 ms
15,000 KB
testcase_34 AC 145 ms
15,160 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

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]);
    }
    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