結果

問題 No.2325 Skill Tree
ユーザー momoyuumomoyuu
提出日時 2023-05-28 13:52:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 646 ms / 3,000 ms
コード長 1,178 bytes
コンパイル時間 4,807 ms
コンパイル使用メモリ 261,144 KB
実行使用メモリ 16,952 KB
最終ジャッジ日時 2023-08-27 08:36:26
合計ジャッジ時間 24,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 260 ms
4,508 KB
testcase_08 AC 175 ms
8,332 KB
testcase_09 AC 297 ms
6,560 KB
testcase_10 AC 222 ms
11,648 KB
testcase_11 AC 297 ms
9,080 KB
testcase_12 AC 546 ms
15,640 KB
testcase_13 AC 547 ms
15,532 KB
testcase_14 AC 545 ms
15,700 KB
testcase_15 AC 544 ms
15,560 KB
testcase_16 AC 544 ms
15,648 KB
testcase_17 AC 538 ms
15,464 KB
testcase_18 AC 533 ms
15,584 KB
testcase_19 AC 534 ms
15,628 KB
testcase_20 AC 530 ms
15,700 KB
testcase_21 AC 539 ms
15,592 KB
testcase_22 AC 549 ms
15,636 KB
testcase_23 AC 551 ms
15,544 KB
testcase_24 AC 548 ms
15,544 KB
testcase_25 AC 544 ms
15,864 KB
testcase_26 AC 549 ms
15,516 KB
testcase_27 AC 628 ms
15,948 KB
testcase_28 AC 632 ms
15,992 KB
testcase_29 AC 627 ms
15,892 KB
testcase_30 AC 630 ms
15,996 KB
testcase_31 AC 625 ms
15,868 KB
testcase_32 AC 597 ms
16,952 KB
testcase_33 AC 614 ms
15,952 KB
testcase_34 AC 615 ms
15,996 KB
testcase_35 AC 626 ms
16,072 KB
testcase_36 AC 617 ms
16,900 KB
testcase_37 AC 646 ms
16,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> l(n,0),a(n,0);
    vector<vector<int>> g(n);
    for(int i = 1;i<n;i++){
        cin>>l[i]>>a[i];
        a[i]--;
        g[a[i]].push_back(i);
    }
    using dat = pair<ll,int>;
    priority_queue<dat,vector<dat>,greater<dat>> que;
    vector<int> vis(n,0);
    que.push(make_pair(0ll,0));
    while(que.size()){
        dat now = que.top();
        que.pop();
        int ni = now.second;
        vis[ni] = 1;
        for(auto&e:g[ni]){
            l[e] = max(l[e],l[ni]);
            que.push(make_pair(l[e],e));
        }
    }
    vector<int> can;
    for(int i = 0;i<n;i++) if(vis[i])can.push_back(l[i]);
    sort(can.begin(),can.end());
    int q;
    cin>>q;
    while(q--){
        int op;
        cin>>op;
        if(op==1){
            int x;
            cin>>x;
            int ni = upper_bound(can.begin(),can.end(),x) - can.begin();
            cout<<ni<<endl;
        }else{
            int x;
            cin>>x;
            x--;
            if(vis[x]==0) cout<<-1<<endl;
            else cout<<l[x]<<endl;
        }
    }


        

     
}
0