結果

問題 No.2325 Skill Tree
ユーザー marblemarble
提出日時 2023-05-28 15:30:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,499 bytes
コンパイル時間 3,006 ms
コンパイル使用メモリ 178,200 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-08 07:56:06
合計ジャッジ時間 13,041 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 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 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2,026 ms
5,376 KB
testcase_08 AC 2,403 ms
8,448 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<int,int>>> g;
vector<int> vis;
int N;
int dfs(int c,int ml,int last){
    if(c == last){
        return ml;
    }
    int ans=-1;
    vis[c] = true;
    for(auto next : g[c]){
        if(vis[next.first]){
            continue;
        }
        ans = dfs(next.first,max(ml,next.second), last);
        if(ans != -1){
            break;
        }
    }
    return ans;
}

int solve(){
    int x,y;
    cin >> x >> y;
    if(x == 1){
        deque<int> co;
        ll ans=1;
        co.push_back(0);
        while(!co.empty()){
            int p=co.front();
            co.pop_front();
            vis[p] = true;
            for(auto next:g[p]){
                if(next.second<=y && !vis[next.first]){
                    ans++;
                    co.push_back(next.first);
                    vis[next.first] = true;
                }
            }
        }
        for(int i=0;i<N;i++){
            vis[i] = false;
        }
        return ans;
    }else{
        ll ans = dfs(0,1,y-1);
        for(int i=0;i<N;i++){
            vis[i] = false;
        }
        return ans;   
    }
}

int main(){
    cin >> N;
    vis.resize(N);
    g.resize(N);
    for(int i=1;i<N;i++){
        int L,A;
        cin >> L >> A;
        A--;
        g[A].push_back({i,L});
        g[i].push_back({A,L});
    }
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int ans = solve();
        cout << ans << endl;
    }
}
0