結果

問題 No.2325 Skill Tree
ユーザー bluebery1001bluebery1001
提出日時 2023-05-28 15:46:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 3,000 ms
コード長 1,999 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 177,912 KB
実行使用メモリ 9,836 KB
最終ジャッジ日時 2023-08-27 12:56:10
合計ジャッジ時間 16,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,476 KB
testcase_01 AC 3 ms
4,520 KB
testcase_02 AC 4 ms
4,552 KB
testcase_03 AC 3 ms
4,568 KB
testcase_04 AC 3 ms
4,432 KB
testcase_05 AC 3 ms
4,524 KB
testcase_06 AC 3 ms
4,476 KB
testcase_07 AC 203 ms
5,232 KB
testcase_08 AC 107 ms
5,964 KB
testcase_09 AC 213 ms
5,340 KB
testcase_10 AC 121 ms
6,756 KB
testcase_11 AC 203 ms
6,172 KB
testcase_12 AC 355 ms
7,724 KB
testcase_13 AC 363 ms
7,872 KB
testcase_14 AC 355 ms
7,728 KB
testcase_15 AC 357 ms
7,760 KB
testcase_16 AC 357 ms
7,888 KB
testcase_17 AC 354 ms
7,760 KB
testcase_18 AC 355 ms
7,720 KB
testcase_19 AC 353 ms
7,892 KB
testcase_20 AC 357 ms
7,764 KB
testcase_21 AC 358 ms
7,832 KB
testcase_22 AC 350 ms
7,796 KB
testcase_23 AC 347 ms
7,760 KB
testcase_24 AC 348 ms
7,852 KB
testcase_25 AC 344 ms
7,768 KB
testcase_26 AC 344 ms
7,812 KB
testcase_27 AC 383 ms
9,836 KB
testcase_28 AC 384 ms
9,760 KB
testcase_29 AC 385 ms
9,552 KB
testcase_30 AC 384 ms
9,400 KB
testcase_31 AC 385 ms
9,488 KB
testcase_32 AC 370 ms
9,076 KB
testcase_33 AC 379 ms
9,640 KB
testcase_34 AC 380 ms
9,696 KB
testcase_35 AC 375 ms
9,044 KB
testcase_36 AC 369 ms
8,800 KB
testcase_37 AC 386 ms
9,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using namespace std;
#include<bits/stdc++.h>
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15);_main(); return 0;}
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class ll> inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; }
template<class ll> inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i, star,fini) for (int i = star; i < fini; i++)
#define ALL(x) std::begin(x), std::end(x)
#define INF ((1LL<<62)-(1LL<<31))
#define bit(x,i)(((x)>>(i))&1)
long double distance(long double xi,long double yi,long double xj,long double yj){return sqrt(1.0*((xi-xj)*(xi-xj))+1.0*((yi-yj)*(yi-yj)));}
vector<ll>needlv(200005,-1);
ll l[200005],a[200005];
void kakutei(ll pos){
    if(needlv[pos]==-2)return;
    if(needlv[pos]!=-1)return;
    if(needlv[a[pos]]>-1){
        needlv[pos]=max(l[pos],needlv[a[pos]]);
    }
    else{
        needlv[pos]=-2;
        kakutei(a[pos]);
        if(needlv[a[pos]]>-1){
            needlv[pos]=max(l[pos],needlv[a[pos]]);
        }

    }
}
void _main(){
    ll n;cin >> n;
    l[0]=0;a[0]=0;needlv[0]=0;
    rep(i,1,n){
        cin >> l[i] >> a[i];
        a[i]--;
    }
    rep(i,0,n){
        kakutei(i);
    }
    map<ll,ll>qone;
    for(ll i:needlv){
        if(i<0)continue;
        qone[i]++;
        
    }
    vector<ll>ans;
    vector<ll>ans_name;
    ll prev = 0;
    for(auto i:qone){
        ans_name.push_back(i.first);
        ans.push_back(prev+i.second);
        prev = ans.back();
    }
    
    ll q;cin >> q;
    while (q--)
    {
        ll t,x;cin >> t;
        if(t==1){
            cin >> x;
            ll pos = upper_bound(ALL(ans_name),x)-ans_name.begin();
            pos--;
            cout<<ans[pos]<<endl;
        }
        else{
            cin >> x;
            cout<<(needlv[x-1]>0?needlv[x-1]:-1)<<endl;
        }
    }
    
}
0