結果

問題 No.2325 Skill Tree
ユーザー CyanmondCyanmond
提出日時 2023-05-28 14:56:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 582 ms / 3,000 ms
コード長 1,224 bytes
コンパイル時間 2,920 ms
コンパイル使用メモリ 213,908 KB
実行使用メモリ 15,440 KB
最終ジャッジ日時 2023-08-27 10:58:15
合計ジャッジ時間 21,889 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 260 ms
4,628 KB
testcase_08 AC 171 ms
7,528 KB
testcase_09 AC 293 ms
6,300 KB
testcase_10 AC 214 ms
10,624 KB
testcase_11 AC 295 ms
8,236 KB
testcase_12 AC 535 ms
14,028 KB
testcase_13 AC 534 ms
14,020 KB
testcase_14 AC 539 ms
13,920 KB
testcase_15 AC 543 ms
13,976 KB
testcase_16 AC 534 ms
13,988 KB
testcase_17 AC 524 ms
14,044 KB
testcase_18 AC 526 ms
14,212 KB
testcase_19 AC 526 ms
14,100 KB
testcase_20 AC 533 ms
14,024 KB
testcase_21 AC 523 ms
14,060 KB
testcase_22 AC 541 ms
14,040 KB
testcase_23 AC 541 ms
13,976 KB
testcase_24 AC 544 ms
14,124 KB
testcase_25 AC 539 ms
14,128 KB
testcase_26 AC 540 ms
13,972 KB
testcase_27 AC 572 ms
15,440 KB
testcase_28 AC 577 ms
15,292 KB
testcase_29 AC 573 ms
15,348 KB
testcase_30 AC 574 ms
15,304 KB
testcase_31 AC 574 ms
15,344 KB
testcase_32 AC 546 ms
15,236 KB
testcase_33 AC 547 ms
15,340 KB
testcase_34 AC 546 ms
15,296 KB
testcase_35 AC 577 ms
15,292 KB
testcase_36 AC 573 ms
15,368 KB
testcase_37 AC 582 ms
15,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include "atcoder/modint"

using i64 = long long;
using Fp = atcoder::modint998244353;

int main() {
    int N;
    std::cin >> N;
    std::vector<int> L(N), A(N);
    std::vector<std::vector<int>> graph(N);
    for (int i = 1; i < N; ++i) {
        std::cin >> L[i] >> A[i];
        --A[i];
        graph[A[i]].push_back(i);
    }
    std::vector<int> dist(N, -1);
    dist[0] = 0;
    std::queue<int> que;
    que.push(0);
    while (not que.empty()) {
        const auto f = que.front();
        que.pop();
        for (const auto t : graph[f]) {
            i64 c = std::max(dist[f], L[t]);
            dist[t] = c;
            que.push(t);
        }
    }
    std::vector<i64> x;
    for (const auto e : dist) if (e != -1) x.push_back(e);
    std::sort(x.begin(), x.end());

    int Q;
    std::cin >> Q;
    while (Q--) {
        int t;
        std::cin >> t;
        if (t == 1) {
            int v;
            std::cin >> v;
            auto itr = std::upper_bound(x.begin(), x.end(), v);
            std::cout << (itr - x.begin()) << std::endl;
        } else {
            int v;
            std::cin >> v;
            --v;
            std::cout << dist[v] << std::endl;
        }
    }
}
0