結果

問題 No.2325 Skill Tree
ユーザー dyktr_06dyktr_06
提出日時 2023-04-15 11:35:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 478 ms / 3,000 ms
コード長 1,202 bytes
コンパイル時間 2,809 ms
コンパイル使用メモリ 209,096 KB
実行使用メモリ 19,564 KB
最終ジャッジ日時 2024-04-19 07:02:56
合計ジャッジ時間 19,916 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 208 ms
5,376 KB
testcase_08 AC 127 ms
9,344 KB
testcase_09 AC 231 ms
7,424 KB
testcase_10 AC 147 ms
13,568 KB
testcase_11 AC 200 ms
10,752 KB
testcase_12 AC 378 ms
18,176 KB
testcase_13 AC 366 ms
18,152 KB
testcase_14 AC 372 ms
18,176 KB
testcase_15 AC 375 ms
18,176 KB
testcase_16 AC 374 ms
18,152 KB
testcase_17 AC 348 ms
18,176 KB
testcase_18 AC 365 ms
18,232 KB
testcase_19 AC 379 ms
18,176 KB
testcase_20 AC 365 ms
18,232 KB
testcase_21 AC 379 ms
18,176 KB
testcase_22 AC 365 ms
18,168 KB
testcase_23 AC 420 ms
18,176 KB
testcase_24 AC 416 ms
18,176 KB
testcase_25 AC 419 ms
18,020 KB
testcase_26 AC 370 ms
18,124 KB
testcase_27 AC 423 ms
19,432 KB
testcase_28 AC 478 ms
19,556 KB
testcase_29 AC 464 ms
19,564 KB
testcase_30 AC 455 ms
19,560 KB
testcase_31 AC 466 ms
19,348 KB
testcase_32 AC 457 ms
19,436 KB
testcase_33 AC 427 ms
19,432 KB
testcase_34 AC 423 ms
19,560 KB
testcase_35 AC 438 ms
19,432 KB
testcase_36 AC 426 ms
19,560 KB
testcase_37 AC 456 ms
19,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

vector<int> l;

vector<vector<int>> G;
vector<int> ans1;

void dfs(int curr, int prev){
    for(auto x : G[curr]){
        if(x == prev){
            continue;
        }
        ans1[x] = max(ans1[curr], l[x]);
        dfs(x, curr);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    G.resize(n);
    l.resize(n);
    ans1.assign(n, -1);

    vector<tuple<int, int, int>> skill(n - 1);
    for(int i = 1; i < n; i++){
        int a; cin >> l[i] >> a; a--;
        G[i].push_back(a);
        G[a].push_back(i);
    }

    ans1[0] = 1;
    dfs(0, -1);

    vector<int> ans2;
    for(int i = 0; i < n; i++){
        if(ans1[i] != -1){
            ans2.emplace_back(ans1[i]);
        }
    }
    sort(ans2.begin(), ans2.end());

    int q; cin >> q;
    while(q--){
        int t; cin >> t;
        if(t == 1){
            int x; cin >> x;
            auto iter = upper_bound(ans2.begin(), ans2.end(), x);
            int k = iter - ans2.begin();
            cout << k << endl;
        }else{
            int y; cin >> y; y--;
            cout << ans1[y] << endl;
        }
    }
}
0