結果

問題 No.2325 Skill Tree
ユーザー ooaiu
提出日時 2025-10-07 16:41:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 196 ms / 3,000 ms
コード長 1,111 bytes
コンパイル時間 7,690 ms
コンパイル使用メモリ 289,232 KB
実行使用メモリ 16,736 KB
最終ジャッジ日時 2025-10-07 16:42:12
合計ジャッジ時間 15,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using ll = long long;
const int maxn = 2<<17;
const ll inf = 2e9;
int N, Q;
int L[maxn],A[maxn];
vector<int> G[maxn];
int dp[maxn];
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> N;
    atcoder::dsu uf(N);
    dp[0] = 0;
    for(int i = 1; i < N; i++) {
        cin >> L[i] >> A[i];
        A[i]--;
        uf.merge(i, A[i]);
        G[A[i]].push_back(i);
        dp[i]=inf;
    }
    cin >> Q;
    {
        queue<int> q;
        q.push(0);
        while(q.size()) {
            int v=q.front();q.pop();
            for(int u:G[v]){
                dp[u]=max(dp[v],L[u]);
                q.push(u);
            }
        }
    }
    vector<int>B;
    for(int i = 0; i < N; i++) if(dp[i]!=inf) B.push_back(dp[i]);
    sort(B.begin(),B.end());
    while(Q--) {
        int op, x;
        cin >> op >> x;
        if(op==1) {
            cout << (upper_bound(B.begin(),B.end(),x)-B.begin())<<"\n";
        } else {
            x--;
            cout<<(dp[x]==inf?-1:dp[x]) <<"\n";
        }
    }

}
0