結果

問題 No.2325 Skill Tree
ユーザー hourenhouren
提出日時 2023-05-28 15:32:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 3,000 ms
コード長 1,391 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 178,712 KB
実行使用メモリ 14,288 KB
最終ジャッジ日時 2023-08-27 12:22:45
合計ジャッジ時間 10,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 38 ms
4,376 KB
testcase_08 AC 42 ms
7,208 KB
testcase_09 AC 50 ms
5,968 KB
testcase_10 AC 66 ms
10,352 KB
testcase_11 AC 63 ms
7,932 KB
testcase_12 AC 122 ms
13,184 KB
testcase_13 AC 121 ms
13,268 KB
testcase_14 AC 124 ms
13,292 KB
testcase_15 AC 128 ms
13,212 KB
testcase_16 AC 125 ms
13,200 KB
testcase_17 AC 124 ms
13,264 KB
testcase_18 AC 121 ms
13,192 KB
testcase_19 AC 118 ms
13,088 KB
testcase_20 AC 122 ms
13,156 KB
testcase_21 AC 125 ms
13,320 KB
testcase_22 AC 127 ms
13,256 KB
testcase_23 AC 128 ms
13,152 KB
testcase_24 AC 123 ms
13,256 KB
testcase_25 AC 125 ms
13,256 KB
testcase_26 AC 121 ms
13,216 KB
testcase_27 AC 192 ms
13,816 KB
testcase_28 AC 194 ms
13,500 KB
testcase_29 AC 189 ms
13,496 KB
testcase_30 AC 197 ms
14,012 KB
testcase_31 AC 197 ms
13,548 KB
testcase_32 AC 181 ms
14,072 KB
testcase_33 AC 189 ms
13,892 KB
testcase_34 AC 182 ms
13,700 KB
testcase_35 AC 191 ms
13,796 KB
testcase_36 AC 194 ms
14,288 KB
testcase_37 AC 204 ms
13,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n;
    vector<vector<int>> g(n);
    vector<int> l(n);
    rep(i,n-1){
        int a;
        cin >> l[i+1] >> a;
        g[a-1].push_back(i+1);
    }
    vector<int> dist(n,INF), r(1,0);
    dist[0] = 0;
    priority_queue<asc(P)> pq;
    pq.push({0,0});
    while(pq.size()){
        int now, d;
        tie(d,now) = pq.top();
        pq.pop();
        if(dist[now]!=d) continue;
        r.push_back(d);
        for(int x:g[now]){
            if(chmin(dist[x], max(dist[now], l[x]))) pq.push({dist[x], x});
        }
    }
    rep(i,n) if(dist[i]==INF) dist[i] = -1;
    cin >> q;
    rep(houren,q){
        int t,x;
        cin >> t >> x;
        if(t==1){
            cout << upper_bound(all(r),x) - r.begin()-1 << '\n';
        }else{
            cout << dist[x-1] << '\n';
        }
    }
    return 0;
}
0