結果

問題 No.2325 Skill Tree
ユーザー hiikunZhiikunZ
提出日時 2023-05-28 13:44:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 3,000 ms
コード長 1,399 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 233,316 KB
実行使用メモリ 24,076 KB
最終ジャッジ日時 2023-08-27 08:23:37
合計ジャッジ時間 19,926 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 205 ms
5,892 KB
testcase_08 AC 130 ms
11,820 KB
testcase_09 AC 230 ms
9,284 KB
testcase_10 AC 166 ms
17,824 KB
testcase_11 AC 230 ms
13,416 KB
testcase_12 AC 425 ms
23,904 KB
testcase_13 AC 423 ms
23,972 KB
testcase_14 AC 434 ms
24,032 KB
testcase_15 AC 427 ms
23,980 KB
testcase_16 AC 425 ms
23,972 KB
testcase_17 AC 421 ms
23,964 KB
testcase_18 AC 417 ms
23,920 KB
testcase_19 AC 423 ms
24,016 KB
testcase_20 AC 425 ms
23,896 KB
testcase_21 AC 423 ms
23,980 KB
testcase_22 AC 421 ms
23,912 KB
testcase_23 AC 427 ms
24,076 KB
testcase_24 AC 423 ms
23,960 KB
testcase_25 AC 430 ms
24,012 KB
testcase_26 AC 430 ms
24,020 KB
testcase_27 AC 505 ms
23,264 KB
testcase_28 AC 497 ms
23,212 KB
testcase_29 AC 492 ms
23,272 KB
testcase_30 AC 494 ms
23,336 KB
testcase_31 AC 507 ms
23,352 KB
testcase_32 AC 485 ms
23,596 KB
testcase_33 AC 485 ms
23,328 KB
testcase_34 AC 490 ms
23,336 KB
testcase_35 AC 495 ms
23,460 KB
testcase_36 AC 503 ms
23,632 KB
testcase_37 AC 498 ms
23,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
const ll MAX = 1e18;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vector<vector<ll>> G(N),C(N);
    for(ll i = 1;i < N;i++){
        ll l,a;
        cin >> l >> a;
        a--;
        G[a].emplace_back(i);
        C[a].emplace_back(l);
    }
    vector<ll> memo(N,MAX);
    priority_queue<tuple<ll,ll>,vector<tuple<ll,ll>>,greater<tuple<ll,ll>>> que;
    que.emplace(0,0);
    while(!que.empty()){
        ll cost,now;
        tie(cost,now) = que.top();
        que.pop();
        if(memo[now] == MAX){
            memo[now] = cost;
            for(ll i = 0;i < G[now].size();i++){
                que.emplace(max(cost,C[now][i]),G[now][i]);
            }
        }
    }
    vector<ll> memo2 = memo;
    sort(memo2.begin(),memo2.end());
    ll Q;
    cin >> Q;
    for(ll i = 0;i < Q;i++){
        ll t,x;
        cin >> t >> x;
        if(t == 1){
            ll ans = upper_bound(memo2.begin(),memo2.end(),x) - memo2.begin();
            cout << ans << endl;
        }
        else{
            ll ans = memo[x - 1];
            if(ans == MAX) cout << -1 << endl;
            else cout << ans << endl;
        }
    }
}
0